同一应用程序中后端和前端(控制器,视图,布局)的分离如何共享CakePHP 3中的模型?
答案 0 :(得分:1)
如果您在终端中使用bin/cake bake
,则可以添加--prefix=Backend
ex controller:bin/cake bake controller NameOfYourTable --prefix=Backend
ex template:bin/cake bake template NameOfYourTable --prefix=Backend
CakePHP将创建子文件夹./src/Controller/Backend/NameOfYourTable
好的名称空间namespace App\Controller\Backend;
和./src/Template/Backend/NameOfYourTable/
加index.ctp
,add.ctp
,edit.ctp
,view.ctp
并在routes.php
ex url: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']
);
});