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?
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
I think these links could be related:
https://github.com/symfony-cmf/RoutingBundle
Category tree in url