duanlie4621 2012-09-06 10:12
浏览 9
已采纳

类别树的路由

I am using the Tree doctrine extension for a category tree and would like to have routes like:

/cat/subcat1/subcat2/subcat3

I can do it defining routes like

/{cat}
/{cat}/{subcat}
/{cat}/{subcat}/{subcat2)
etc...

But is there a more elegant and general way of implementing this? A system that can accept an unlimited number of levels?

  • 写回答

2条回答 默认 最新

  • dongzuoyue6556 2012-09-06 10:33
    关注

    What you can do is accepting slashes in your routing parameters (for this route only). It involves that you can't queue any other parameter as slash separator will be seen as being part of category parameter...

    So, how to manage slashes in a routing parameter :

    _hello:
        pattern: /category/{category}
        defaults: { _controller: AcmeDemoBundle:Demo:category }
        requirements:
            category: ".+"
    

    Calling /category/cat1/sub1/sub2 will call DemoController::categoryAction($category) method with 'cat1/sub1/sub2' as $category parameter. Just use your own code to decode !

    Code sample found on official doc : http://symfony.com/doc/2.0/cookbook/routing/slash_in_parameter.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建