Search code examples
phpsymfonysymfony-routing

Symfony, dynamic routing


I have a symfony project with multiple skins/templates that have their own routes, does anyone have an idea for a correct setup?

  • Every skin/template is its own bundle, since its not just skins and assets, but maybe also services that might exist in some skins.
  • Hostname decides the skin.
  • Using a custom RouteLoader to load the route.yml of the target bundle.

The custom RouteLoader does the job--but the generated routes are getting cached, and as far as i understand, there is no way to prevent route caching.

Some suggestions are:

  • Creating a /{dynamic} route, so manually form routes.. But i dont want to throw away that piece of functionality of the router, or refactor the entire project..
  • Prefix the routes with the template identifier. This would require me to load all route.yml files, which isnt possible since their share paths.

Anyone? I cant go with multiple projects really, the amount of skins will be around 20-30~.

The reason for this setup is because its a target of Content-as-a-Service .. service, multiple clients use the project as a platform, and their setting decides which templates gets used.


Solution

  • It sounds like you want to dynamically load bundles based on the host name? Not going to happen with Symfony 2 because of the caching. Especially the services.

    Your best bet is to setup an app for each skin and then do some url majic to execute the desired app.php file. Clearly since you have defined a bundle for each skin then there is a finite number so having multiple apps should not be much or a burden.

    It's possible that you might be able to work around the template issue. You would still need to load all your skin bundles but you could futz around with the template names or paths and probably get something to work.

    But services? Unless you start appending host names to service id's then I don't see any work around.