如何在cakephp 3.0中做后端和前端架构?
How to Do backend and Frontend architectures in cakephp 3.0?
同一个应用程序中的后端和前端(控制器、视图、布局)如何在 CakePHP 3 中共享模型?
如果您在终端中使用bin/cake bake
,您可以添加--prefix=Backend
前控制器:bin/cake bake controller NameOfYourTable --prefix=Backend
ex 模板: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
中添加您的 url 前缀
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']
);
});
同一个应用程序中的后端和前端(控制器、视图、布局)如何在 CakePHP 3 中共享模型?
如果您在终端中使用bin/cake bake
,您可以添加--prefix=Backend
前控制器:bin/cake bake controller NameOfYourTable --prefix=Backend
ex 模板: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']
);
});