在同一个应用程序中,后端和前端(控制器、视图、布局)如何分离共享CakePHP 3中的模型?
发布于 2016-03-02 15:17:16
如果在终端中使用bin/cake bake,则可以添加--prefix=Backend。
前控制器:bin/cake bake controller NameOfYourTable --prefix=Backend
实例模板:bin/cake bake template NameOfYourTable --prefix=Backend
CakePHP将使用良好的命名空间namespace App\Controller\Backend;创建子文件夹./src/Controller/Backend/NameOfYourTable,使用index.ctp、add.ctp、edit.ctp、view.ctp创建./src/Template/Backend/NameOfYourTable/。
并在routes.php中添加urls前缀
出口网址: www.domain.tld/backend/nameofyourcontroller/
Router::prefix('backend', function($routes) {
$routes->connect(
'/',
['controller' => 'NameOfYourController', 'action' => 'index']
);
$routes->connect(
'/:controller',
['action' => 'index'],
['routeClass' => 'InflectedRoute']
);
$routes->connect(
'/:controller/:action/*',
[],
['routeClass' => 'InflectedRoute']
);
});https://stackoverflow.com/questions/35721803
复制相似问题