I'm using Phalcon php. I have to try to use the multi modules architecture. I have a frontend and backend. The frontend app is the default module. But I don't understand something about the other modules. If I have 50 controllers in the backend with 10 actions by controllers I have to define all routes for the backend module ?
2条回答 默认 最新
- dongxian2863 2016-04-08 21:29关注
For your backend routes you don't have to define 50+ different routes to match all your controller / action combinations. You can mostly stick with the default routes Phalcon provides.
This is an example that might fit your needs. I am not sure what your exact project structure is. But going from the example you provided, try this:
$router = new Phalcon\Mvc\Router(); // set the defaults, so Phalcon knows where to start and where to fall back to $router->setDefaultModule('frontend'); $router->setDefaultNamespace('Apps\Frontend\Controllers'); $router->setDefaultAction("index"); $router->setDefaultController("index"); $router->removeExtraSlashes(true); /* ----------------------------------------------------- */ /* ------------------ FRONTEND ROUTES ------------------ */ /* ----------------------------------------------------- */ $router->add('/([a-zA-Z\-]+)/([a-zA-Z\-]+)/:params', [ 'module' => 'frontend', 'namespace' => 'Apps\Frontend\Controllers', 'controller' => 1, 'action' => 2, 'params' => 3 ]); /* ----------------------------------------------------- */ /* ------------------ BACKEND ROUTES ------------------- */ /* ----------------------------------------------------- */ // to keep your routes.php file clean, // you can create a separate router group for your backend routes. $backend = new Phalcon\Mvc\Router\Group(); $backend->setPrefix('/backend'); // for a backend route with a controller $backend->add('/([a-zA-Z\-]+)', [ 'module' => 'backend', 'namespace' => 'Apps\Backend\Controllers', 'controller' => 1, 'action' => 'index' ]); // for a backend route with a controller/action $backend->add('/([a-zA-Z\-]+)/([a-zA-Z\-]+)', [ 'module' => 'backend', 'namespace' => 'Apps\Backend\Controllers', 'controller' => 1, 'action' => 2 ]); // for a backend route with a controller/action/parameter $backend->add('/([a-zA-Z\-]+)/([a-zA-Z\-]+)/:params', [ 'module' => 'backend', 'namespace' => 'Apps\Backend\Controllers', 'controller' => 1, 'action' => 2, 'params' => 3 ]); // add your backend routes to the main router. $router->mount($backend);
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥20 @microsoft/fetch-event-source 流式响应问题
- ¥15 ogg dd trandata 报错
- ¥15 高缺失率数据如何选择填充方式
- ¥50 potsgresql15备份问题
- ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
- ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
- ¥60 pb数据库修改与连接
- ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
- ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
- ¥20 神经网络Sequential name=sequential, built=False