【问题标题】:How to Do backend and Frontend architectures in cakephp 3.0?如何在 cakephp 3.0 中做后端和前端架构?
【发布时间】:2016-03-01 11:35:01
【问题描述】:

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

【问题讨论】:

  • 诸如“tutorial”之类的术语和诸如“我希望你为我做这个和那个”之类的措辞将使您的问题得到解决并且被否决快速地。您可能需要查看asking guide,了解您应该在 StackOverflow 上询问的内容和方式。

标签: frontend cakephp-3.0 backend


【解决方案1】:

如果您在终端中使用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.ctpadd.ctpedit.ctpview.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']
    );
});

【讨论】:

猜你喜欢
  • 2021-05-08
  • 1970-01-01
  • 2021-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-17
  • 2011-04-12
  • 2015-06-09
相关资源
最近更新 更多