Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to handle routing for CMS-like project in Symfony2

I'm trying to build an Symfony2 application, that have CMS features. I've got three entities (among others) which are : Page, Category, Post (classic ones, huh ?)

I would like to have the following routing :

Page : /{slug} (slug is a Page entity field)

Category : /{slug} (slug is a Category entity field)

Post : /{slug} (slug is a Post entity field)

However, this will never work, because Symfony2 router, will match the first route that corresponds to the /{slug} pattern.

I would like to know, what is the best pratice to handle these cases. I'm aware of Symfony CMF, but I do not want use this kind of massive tool (as it contains too many bundles which I'm not willing to use).

Thanks in advance for your answers

like image 422
user3640804 Avatar asked Jan 24 '26 17:01

user3640804


1 Answers

You will have to use a custom route loader to do this, check the cookbook article:

http://symfony.com/doc/current/cookbook/routing/custom_route_loader.html

The CMF project uses its own dynamic router which you could use without the full CMF stack also:

http://symfony.com/doc/current/cmf/bundles/routing/dynamic.html

like image 82
gezpage Avatar answered Jan 27 '26 08:01

gezpage



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!