Routing for category tree

放肆的年华 提交于 2019-12-05 02:55:45

问题


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?


回答1:


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




回答2:


I think these links could be related:

https://github.com/symfony-cmf/RoutingBundle

Category tree in url



来源:https://stackoverflow.com/questions/12297762/routing-for-category-tree

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!