KvAdmin plugin for CakePHP 5 projects based on the Tabler Admin Template.
First, create a CakePHP ~5.4 project, then install the KvAdmin plugin:
composer create-project --prefer-dist cakephp/app:~5.4 my_app_name
cd my_app_name
composer require kavezoo/kvadminAdd the plugin to your src/Application.php file:
public function bootstrap(): void
{
parent::bootstrap();
// Load more plugins here
$this->addPlugin('KvAdmin', ['routes' => true, 'bootstrap' => true]);
}Add the following lines to the end of your config/bootstrap.php file:
use Cake\Core\Configure;
Configure::write('Bake.theme', 'KvAdmin');
Configure::write('Session', [
'defaults' => 'php',
'cookie' => 'NameOfCookie',
'timeout' => 4320, // 3 days
]);Add the KvAdmin helpers to src/View/AppView.php:
public function initialize(): void
{
parent::initialize();
$this->loadHelper('KvAdmin.SystemIcon');
$this->loadHelper('KvAdmin.Icon');
$this->loadHelper('KvAdmin.KvForm');
}Create a new directory: src/Controller/Admin/
Create src/Controller/Admin/AppController.php with the following content:
<?php
declare(strict_types=1);
namespace App\Controller\Admin;
use KvAdmin\Controller\AppController as KvAdminAppController;
class AppController extends KvAdminAppController
{
public function initialize(): void
{
parent::initialize();
}
}Add the Admin prefix in config/routes.php:
$routes->prefix('Admin', function (RouteBuilder $builder) {
$builder->setRouteClass(DashedRoute::class);
$builder->connect('/', ['controller' => 'Cities', 'action' => 'index']);
$builder->fallbacks();
});Now you can bake your models, controllers, and templates using the Tabler theme:
bin/cake bake model all
bin/cake bake controller all --prefix admin
bin/cake bake template all --prefix adminIf you need additional prefixes (like Member), follow the same pattern:
- Add the prefix to
config/routes.php:
$routes->prefix('Member', function (RouteBuilder $builder) {
$builder->setRouteClass(DashedRoute::class);
$builder->connect('/', ['controller' => 'Clubs', 'action' => 'index']);
$builder->fallbacks();
});- Create
src/Controller/Member/AppController.php:
<?php
declare(strict_types=1);
namespace App\Controller\Member;
use KvAdmin\Controller\AppController as KvAdminAppController;
class AppController extends KvAdminAppController
{
public function initialize(): void
{
parent::initialize();
}
}- Bake files for the new prefix:
bin/cake bake controller all --prefix member
bin/cake bake template all --prefix memberTo customize headers, footers, or navigation, copy the default elements from the plugin into your project's prefix directory (e.g. templates/Admin/element/):
mkdir -p templates/Admin/element
cp vendor/kavezoo/kvadmin/templates/element/header.php templates/Admin/element/header.php
cp vendor/kavezoo/kvadmin/templates/element/topheader.php templates/Admin/element/topheader.php
cp vendor/kavezoo/kvadmin/templates/element/footer.php templates/Admin/element/footer.php
cp vendor/kavezoo/kvadmin/templates/element/topheader_user_menu.php templates/Admin/element/topheader_user_menu.phpBuilt with Tabler UI. Enjoy it!