如果您在终端中使用bin/cake bake,则可以添加--prefix=Backend
前控制器:bin/cake bake controller NameOfYourTable --prefix=Backend
前模板: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中添加您的网址前缀
前网址: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']
);
});