如何在cakephp 3.0中执行后端和前端架构?

时间:2016-03-01 11:35:02

标签: frontend cakephp-3.0 backend

同一应用程序中后端和前端(控制器,视图,布局)的分离如何共享CakePHP 3中的模型?

1 个答案:

答案 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.ctpadd.ctpedit.ctpview.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']
    );
});