You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require --dev atelfoto/template-admin
// src/Application.php
public function bootstrap()
{
$this->addPlugin('Admin');
}
Or Execute the following line in your shell command bash!
bin/cake plugin load Admin
//config/routes
Router::prefix('admin', function ($routes)
{
$routes->connect('/', ['controller' => 'Dashboards', 'action' => 'index']);
$routes->fallbacks(DashedRoute::class);
});
// src/controller/AppController.php
public function beforeFilter(Event $event)
{
if (!is_null($this->request->getParam('prefix'))) {
$prefix = explode('/', $this->request->getParam('prefix'))[0];
switch ($prefix) {
case 'admin':
$this->viewBuilder()->setLayout('admin');
$this->viewBuilder()->setTheme('Admin');
break;
}
}
}
// src/View/AppView.php
public function initialize()
{
$this->loadHelper('Form', [
'templates' => 'Admin.form-template',
]);
}
add this line
// config/bootstrap.php
Configure::load('Admin.config-dist', 'default', false);
below this line
Configure::load('app', 'default', false);
bin/cake migrations migrate -p Admin
bin/cake migrations seed -p Admin
Or for each seed
bin/cake migrations seed --seed UsersSeed -p Admin
bin/cake migrations seed --seed HelpsSeed -p Admin
bin/cake migrations seed --seed MenusSeed -p Admin
Copy this Model
cp -R vendor/atelfoto/template-admin/src/Model/* src/Model/
And this Controller
cp -r vendor/atelfoto/template-admin/src/Controller/Admin/* src/Controller/Admin/
bin/cake bake model examples
// ex. Examples for actions and prefix admin (with fields name:string and online:boolean ).
bin/cake bake controller Examples --actions index,view,add,edit,delete,deleteAll,online, --prefix admin -t Admin
For a Table with behavior Tree add moveUp and moveUp in --actions
bin/cake bake controller Examples --actions index,view,add,edit,delete,deleteAll,moveUp,moveDown,online, --prefix admin -t Admin
In controller/Admin/ExamplesController.php in the actions Add and edit change this line
$parentMenus = $this->Examples->ParentMenus->find('list', ['limit' => 200]);
for this
$parentMenus = $this->Menus->ParentMenus->find(
'treeList',
[
'spacer' => "---- ",
]
);
bin/cake bake template Examples --prefix admin -t Admin
For Table with behavior Tree delete this lines.
//template/Admin/Examples/add.ctp
//and
//template/Admin/examples/edit.ctp
echo $this->Form->control('controller');
echo $this->Form->control('online');
and this line
//Template/Admin/Menus/index.ctp
<td><?= h($menu->online); ?></td>
In a Table and the function initialize add this line.
$this->addBehavior('Admin.Sluggable');