doupingpeng7567 2015-07-27 08:03
浏览 70

如何在Symfony2中实现动态路由?

we have a CMS system build on top of symfony2 and I've been struggling with routing problem, when you would like to implement behavior similiar to every CMS system using friendly URL slug as identifier of entity.

Let's say I have multiple bundles, each of them taking care of their stuff and entities. How can I use their own controllers with dynamic route param slug?

For example, I have a base slug controller with route "/{_slug}/" with lowest priority. So it can found entity by slug in repositories which knows about, but this solution is not flexible. And also it kind of degrading controllers, because now you have only one master controller, instead of deffering the logic to each controller of each bundle.

I found several ideas of approach to this problem.

  1. Load routes from database - a little worse performance, no cached routes
  2. Add dynamic loader of routes - Too much code, worse control of slugs
  3. Custom router, which will be used before symfony core CMF router - so far I've found a little information about this solution

I've found several topic, that tries to cover this problem:

  • 写回答

1条回答 默认 最新

  • dream_high1026 2015-08-02 11:02
    关注

    If you haven't already, I suggest to take a look at the "Dynamic Router" from the RoutingBundle included in the Symfony CMF project.

    Since the CMF project is about building CMS functionalities on top of Symfony, I think it may fit your needs.

    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?