Search by

cahyadsn / ci4basic

cahyadsn

CodeIgniter 4 Basic Boilerplate based on AdminLTE 3 with user management, roles, permissions, ...

Package info

github.com/cahyadsn/ci4basic

pkg:composer/cahyadsn/ci4basic

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

dev-main 2026-09-14 04:54 UTC

This package is auto-updated.

Last update: 2026-09-14 05:01:00 UTC


README

PHP Version CodeIgniter Bootstrap Font Awesome License: MIT

ci4basic is an open-source, extensible back-office administration panel boilerplate for CodeIgniter 4. Built on top of AdminLTE 3, upgraded to modern Bootstrap 5 and Font Awesome 7, it provides out-of-the-box user management, role-based access control (RBAC) via Myth/Auth, a dynamic drag-and-drop menu manager, and customizable themes.

Features

  • Modern UI / UX:
    • Clean backend interface based on AdminLTE 3.
    • Fully upgraded to Bootstrap 5.3.3 (clean flexbox layouts, modern modal and dropdown behaviors).
    • High-resolution icon library powered by Font Awesome 7.3.1.
    • Responsive tables with DataTables (Bootstrap 5 styling) including server-side search, sort, and pagination.
  • Authentication & RBAC (Role-Based Access Control):
    • Built on Myth/Auth (^1.2).
    • Google SSO Integration: Seamless single sign-on powered by Hybridauth v3 with automatic account linking and optional auto-registration.
    • User management: create, edit, activate/deactivate, and delete users.
    • Role management: create custom roles and assign granular permissions via an interactive Bootstrap Dual Listbox.
    • Permission management: dynamic permission assignment with instant modal editing.
    • User self-service profile management (avatar update, password change, personal details).
  • Dynamic Hierarchical Menu Manager:
    • Drag-and-drop menu tree sorting using jQuery Nestable.
    • Font Awesome icon selector integrated via FontAwesome Iconpicker.
    • Role-based menu visibility (menus automatically appear only to permitted roles).
  • Configurable & Extensible:
    • Centralized configuration file (Config/Boilerplate.php) for navbar styles, sidebar theme, app branding, and default landing routes.
    • Easy layout extension using CodeIgniter 4 view sections (content, content-header, css, js).
  • Localization (i18n):
    • Built-in multi-language support (English and Indonesian).
    • Localized DataTables language packs.

Requirements

Ensure your environment satisfies the following requirements:

Requirement Minimum Version
PHP ^8.2 (PHP 8.2, 8.3, or higher)
CodeIgniter ^4.7 (tested with CI 4.7.4)
Database MySQL (5.7+ / 8.0+), MariaDB (10.3+), SQLite3, or PostgreSQL
PHP Extensions intl, mbstring, json, curl, and your database driver (pdo_mysql, mysqli, or sqlite3)
Composer 2.0+

Installation

Step 1: Install via Composer

In your CodeIgniter 4 project root:

composer require cahyadsn/ci4basic

Step 2: Database & Environment Setup

Verify that your .env file contains your database connection details and proper app.baseURL:

app.baseURL = 'http://localhost:8080/'

database.default.hostname = localhost
database.default.database = my_ci4_db
database.default.username = root
database.default.password = 
database.default.DBDriver = MySQLi

Step 3: Run the Boilerplate Installer

Execute the following spark command in your terminal:

php spark boilerplate:install

This single command automatically:

  1. Publishes configuration files to app/Config/Boilerplate.php and app/Config/GoogleSSO.php.
  2. Publishes and runs all database migrations for authentication, users, roles, permissions, menus, and OAuth SSO identities (auth_oauth_identities).
  3. Seeds the database with default roles, permissions, menus, and initial user accounts.

Step 4: Register Filters

Open app/Config/Filters.php and register the aliases for authentication and authorization:

public array $aliases = [
    'csrf'          => \CodeIgniter\Filters\CSRF::class,
    'toolbar'       => \CodeIgniter\Filters\DebugToolbar::class,
    'honeypot'      => \CodeIgniter\Filters\Honeypot::class,
    // Add these three filters:
    'login'         => \Myth\Auth\Filters\LoginFilter::class,
    'role'          => \cahyadsn\ci4basic\Filters\RoleFilter::class,
    'permission'    => \cahyadsn\ci4basic\Filters\PermissionFilter::class,
];

Default Accounts & Seed Data

Once installed, the following default accounts are seeded:

Role Username Password Email Description
Admin admin super-admin admin@admin.com Has full access to all back-office management features.
Member user super-user user@user.com Standard user account without administration privileges.

Warning

Production Security: Make sure to change the default passwords or delete default accounts immediately after initial deployment.

Pre-Configured Routes & Permissions

The package registers the following routes under the /admin prefix:

Method URI Controller Action Permission
GET /admin Configurable in Boilerplate.php back-office
GET/POST /admin/user/profile UserController::profile back-office
RESOURCE /admin/user/manage UserController manage-user
RESOURCE /admin/role RoleController role-permission
RESOURCE /admin/permission PermissionController role-permission
RESOURCE /admin/menu MenuController menu-permission
PUT /admin/menu-update MenuController::new menu-permission
GET /sso/google GoogleSSOController::redirect None (Public)
GET /sso/google/callback GoogleSSOController::callback None (Public)

Google Single Sign-On (SSO) Setup

ci4basic integrates Google Single Sign-On using Hybridauth v3.

1. Obtain OAuth 2.0 Credentials

  1. Go to the Google Cloud Console Credentials.
  2. Create an OAuth 2.0 Client ID (Web application).
  3. Set Authorized redirect URIs to:
    http://localhost:8080/sso/google/callback
    
    (Replace http://localhost:8080/ with your production domain when deploying).

2. Configure Environment Variables

Add your Google credentials to your .env file:

# Google SSO Configuration
google.clientId = 'YOUR_GOOGLE_CLIENT_ID.apps.googleusercontent.com'
google.clientSecret = 'YOUR_GOOGLE_CLIENT_SECRET'

# Optional customizations:
google.enabled = true
google.autoRegister = true
google.defaultRole = 'member'

Alternatively, you can customize settings directly in app/Config/GoogleSSO.php. When google.clientId is configured, the "Sign in using Google" button will automatically appear on the login page.

Configuration

After running boilerplate:install, you can customize settings in app/Config/Boilerplate.php and app/Config/GoogleSSO.php:

Boilerplate Configuration (app/Config/Boilerplate.php)

namespace Config;

use CodeIgniter\Config\BaseConfig;

class Boilerplate extends BaseConfig
{
    // Application branding name
    public $appName = 'Boilerplate';

    // Dashboard entry route configuration
    public $dashboard = [
        'namespace'  => 'cahyadsn\ci4basic\Controllers',
        'controller' => 'DashboardController::index',
        'filter'     => 'permission:back-office',
    ];

    // DataTables localization ('Indonesian', 'English', etc.)
    public $i18n = 'Indonesian';

    // Theme and layout appearance
    public $theme = [
        'body-sm' => false,
        'navbar'  => [
            'bg'     => 'white',    // white, primary, dark, etc.
            'type'   => 'light',    // light, dark
            'border' => true,
            'user'   => [
                'visible' => true,
                'shadow'  => 0,
            ],
        ],
        'sidebar' => [
            'type'    => 'dark',    // light, dark
            'shadow'  => 4,         // 0 - 4
            'border'  => false,
            'compact' => true,
            'links'   => [
                'bg'     => 'primary',
                'shadow' => 1,
            ],
            'brand'   => [
                'bg'   => 'white',
                'logo' => 'vendor/cahyadsn/ci4basic/assets/icon.png',
            ],
            'user'    => [
                'visible' => true,
                'shadow'  => 2,
            ],
        ],
        'footer'  => [
            'fixed'  => false,
            'vendor' => 'cahyadsn',
            'link'   => 'https://github.com/cahyadsn/ci4basic',
        ],
    ];
}

Google SSO Configuration (app/Config/GoogleSSO.php)

namespace Config;

use CodeIgniter\Config\BaseConfig;

class GoogleSSO extends BaseConfig
{
    // Enable or disable Google SSO
    public bool $enabled = true;

    // Google OAuth 2.0 Client ID (can also be set via .env: google.clientId)
    public string $clientId = '';

    // Google OAuth 2.0 Client Secret (can also be set via .env: google.clientSecret)
    public string $clientSecret = '';

    // Redirect callback URL (default: site_url('sso/google/callback'))
    public string $callbackUrl = '';

    // OAuth 2.0 scopes
    public array $scope = ['email', 'profile'];

    // Default role assigned to newly auto-registered users
    public string $defaultRole = 'member';

    // Automatically register user if email does not exist in database
    public bool $autoRegister = true;
}

Creating Custom Admin Pages

To build new back-office modules that integrate seamlessly with the theme and permissions:

1. Create a Controller

namespace App\Controllers\Admin;

use App\Controllers\BaseController;

class ProductsController extends BaseController
{
    public function index()
    {
        $data = [
            'title' => 'Products Management',
        ];

        return view('admin/products/index', $data);
    }
}

2. Create the View

Extend the boilerplate master layout (cahyadsn\ci4basic\Views\layout\index) and inject content into the view sections:

<?= $this->extend('cahyadsn\ci4basic\Views\layout\index') ?>

<!-- Optional: Custom Page Header -->
<?= $this->section('content-header') ?>
<div class="row mb-2">
    <div class="col-sm-6">
        <h1 class="m-0"><?= esc($title) ?></h1>
    </div>
    <div class="col-sm-6">
        <ol class="breadcrumb float-sm-end">
            <li class="breadcrumb-item"><a href="<?= base_url('admin') ?>">Home</a></li>
            <li class="breadcrumb-item active">Products</li>
        </ol>
    </div>
</div>
<?= $this->endSection() ?>

<!-- Main Content Area -->
<?= $this->section('content') ?>
<div class="card card-outline card-primary">
    <div class="card-header">
        <h3 class="card-title">Product List</h3>
        <div class="card-tools">
            <a href="<?= base_url('admin/products/new') ?>" class="btn btn-primary btn-sm">
                <i class="fas fa-plus me-1"></i> Add Product
            </a>
        </div>
    </div>
    <div class="card-body">
        <p>Your products table or content goes here.</p>
    </div>
</div>
<?= $this->endSection() ?>

<!-- Optional: Page-specific JavaScript -->
<?= $this->section('js') ?>
<script>
    console.log('Products page loaded.');
</script>
<?= $this->endSection() ?>

3. Register the Route

In app/Config/Routes.php:

$routes->group('admin', ['filter' => 'permission:back-office'], function ($routes) {
    $routes->get('products', 'Admin\ProductsController::index');
});

4. Add to Dynamic Menu

  1. Log in to the admin panel with an administrative account.
  2. Navigate to Menu Management (/admin/menu).
  3. Add a new menu item:
    • Title: Products
    • Route: admin/products
    • Icon: Choose any Font Awesome icon (e.g. fas fa-boxes-stacked)
    • Roles: Select the roles allowed to see this menu item.
  4. Drag and position the item within your sidebar hierarchy, then click Save.

Running Tests

Automated tests are powered by PHPUnit 11:

# Run tests with composer
composer test

# Or run PHPUnit directly
./vendor/bin/phpunit

License

This package is open-source software licensed under the MIT License.