2016-03-01 58 views
2

在同一个应用程序中,后端和前端(控制器,视图,布局)如何分离CakePHP 3中的模型?如何在cakephp 3.0中执行后端和前端架构?

+1

诸如 “_tutorial_” 等“_I措辞要你做这个那对我来说“会让你的问题关闭并且快速下降。您可能需要检查[**问题指南**](http://stackoverflow.com/help)了解您应该在StackOverflow上提出什么问题以及如何解决问题。 – ndm

回答

1

,如果你在你的终端使用bin/cake bake,您可以添加--prefix=Backend

EX控制器: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 /后端/ 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'] 
    ); 
}); 
+0

谢谢!它的作品 – Ikbel

+0

不客气@Ikbel,你可以解决这个帖子?像http://s18.postimg.org/fgz3lf8ad/Screen_Shot_2016_03_03_at_10_02_51.png – eclaude