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);
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 对接wps接口实现获取元数据
- ¥20 给自己本科IT专业毕业的妹m找个实习工作
- ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
- ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
- ¥50 mac mini外接显示器 画质字体模糊
- ¥15 TLS1.2协议通信解密
- ¥40 图书信息管理系统程序编写
- ¥20 Qcustomplot缩小曲线形状问题
- ¥15 企业资源规划ERP沙盘模拟
- ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在