0

I would like to develop a CMS using Symfony 2 that has 2 bundles: one for pages and one for galleries (in the future there will be more bundles). All pages and galleries will be stored in database and they will be dynamically changed. I have two question about routing in this situation.

  1. What is a good pattern for adding a dynamical routing (using database) in symfony2? Is it a good practice to develop a central controller (dispatcher) that will redirect user to the correct bundle?
  2. I found in documentation that there is "CMF Dynamic Routing" http://symfony.com/doc/master/cmf/bundles/routing/dynamic.html is it possible to use it without any other part of CMF?

Regards,

Mdt
  • 121
  • 6
  • 2
    Why do you need something *dynamic*? You can format the URL as you want, with records ids or slug: http://symfony.com/doc/current/book/routing.html#routing-in-action – A.L Apr 27 '15 at 12:55
  • 1
    Yes, but they look almost the same: @Route("/{slug}") for page and @Route("/{slug}") for gallery – Mdt Apr 28 '15 at 13:13
  • I think that you should keep it simple and add a suffix to differentiate the 2 types of URLs. Or you can add a central table to store URLs and link it to the other entities, it will require less database access that having to search URL in each entity table. – A.L Apr 28 '15 at 13:18
  • for example @Route("/p-{slug}") for page and @Route("/g-{slug}") for gallery I'm not sure, but I think it will have a negative influence on SEO – Mdt Apr 28 '15 at 13:24
  • This might be a solution for you http://www.tomasvotruba.cz/blog/2016/02/25/modular-routing-in-symfony – Tomas Votruba Feb 27 '16 at 03:02
  • I thought about keeping url in database (so it will easier to add new cms pages via admin panel), however I didn't know about ModularRouting I will read about it. Thank you – Mdt Feb 28 '16 at 09:54

1 Answers1

1

regarding point 2: correct, you can use the CMF Routing component independently and its a good way to go.

You just need to write a ContentAwareGenerator to generate Url's for you and a RouteProvider to create Route objects matching your urls.

Bartłomiej Wach
  • 1,968
  • 1
  • 11
  • 17
  • @Mdt don't hesitate to ask questions on the symfony cmf mailinglist or in the RoutingBundle github repository if you need help figuring out variant 2. – dbu Apr 28 '15 at 06:16