atelfoto/template-admin

CakePHP 管理插件

安装: 9

依赖: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 0

开放问题: 0

语言:JavaScript

类型:cakephp-plugin

1.0.6 2020-08-16 20:00 UTC

This package is auto-updated.

Last update: 2024-09-17 04:44:18 UTC


README

安装

您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。

安装 composer 包的推荐方法是

composer require --dev atelfoto/template-admin

启用插件

// src/Application.php

public function bootstrap()
{
    $this->addPlugin('Admin');
}

或者在您的 shell 命令行 bash 中执行以下行!

bin/cake plugin load Admin

启用前缀 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',
        ]);
    }

配置

在此行下方添加此行

// config/bootstrap.php

Configure::load('Admin.config-dist', 'default', false);

在此行下方

Configure::load('app', 'default', false);

烘焙

迁移表

bin/cake migrations migrate -p Admin
bin/cake migrations seed -p Admin

或对于每个种子

bin/cake migrations seed --seed UsersSeed -p Admin
bin/cake migrations seed --seed HelpsSeed -p Admin
bin/cake migrations seed --seed MenusSeed -p Admin

复制此模型

cp -R vendor/atelfoto/template-admin/src/Model/* src/Model/

以及此控制器

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

对于具有行为树的行为表,在 --actions 中添加 moveUp 和 moveUp。

bin/cake bake controller Examples --actions index,view,add,edit,delete,deleteAll,moveUp,moveDown,online, --prefix admin -t Admin

在控制器/Admin/ExamplesController.php 中,在添加和编辑操作中更改此行

$parentMenus = $this->Examples->ParentMenus->find('list', ['limit' => 200]);

为此

$parentMenus = $this->Menus->ParentMenus->find(
            'treeList',
            [
                'spacer' => "---- ",
            ]
        );

模板

模板示例

bin/cake bake template Examples --prefix admin -t Admin

对于具有行为树的表,删除这些行。

//template/Admin/Examples/add.ctp
//and
//template/Admin/examples/edit.ctp
echo $this->Form->control('controller');
echo $this->Form->control('online');

以及此行

//Template/Admin/Menus/index.ctp

<td><?= h($menu->online); ?></td>

行为 Sluggable

在表中函数 initialize 中添加此行。

$this->addBehavior('Admin.Sluggable');

Page menus

Page menus

Page menus