这适用于3.1.2的CakePHP
第1步:设置上面admin
前缀的路由你的正常/
// code ...
// for prefix admin
Router::prefix('admin', function ($routes) {
// All routes here will be prefixed with `/admin`
// And have the prefix => admin route element added.
$routes->fallbacks('InflectedRoute');
});
// for the non-prefix routes
Router::scope('/', function ($routes) {
// more code ...
第2步:创建一个名为管理您的Controllers文件夹
文件夹里面
在那里转储适当的控制器。
Controller
|
|------Admin
| |
| |----- AppController.php
| |---- ProductsController.php // this handles all the admin actions
|
|----- ProductsController.php // this handles the non-prefix actions
第3步:确保管理文件夹内所有的控制器使用的命名空间namespace App\Controller\Admin;
第4步:管理文件夹内的所有控制器扩展的AppController 内管理文件夹
第5步:在您的应用/控制器/管理员/ AppController的beforeFilter中添加此项
public function beforeFilter(Event $event)
{
$this->viewBuilder()->theme('AppUI'); // AppUI is my plugin name
$this->viewBuilder()->layout('AppUI.backend');
}
为什么这项作品?
因为主题现在应该是一个插件。见http://book.cakephp.org/3.0/en/views/themes.html#themes
我引用
主题CakePHP中只是插件,专注于提供模板 文件。
像这样:
plugins
|
|------AppUI
| |
| |----- src
| |
| |---- Template
| |---- Layout
| |---- backend.ctp
你能告诉你的routes.php文件的文件? – 2015-04-04 12:02:08
目前在route.php中没有任何内容,除了默认情况。我尝试添加('''$ routes-> connect('/ admin',['plugin'=>'admin','controller'=>'Pages','action'=>'display','home ']);''')但它不起作用。我的管理插件也有它的route.php – Salines 2015-04-04 12:13:20