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.
- Load routes from database - a little worse performance, no cached routes
- Add dynamic loader of routes - Too much code, worse control of slugs
- 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: