Search code examples
configurationroutesloadsymfony-1.4symfony-plugins

symfon 1.4 load different routing.yml based on url parameter inside a plugin


I have a plugin and i need to load a different routing.yml file based on a variable in the query string.

Example:

if($request->getParameter('page'){
 // use routingPage.yml
}
else{
 // use another routing.yml
}

So, If the page parameter in url the url_for('@route1'), will return one url, else the same url_for('@route1') would return other url.

How can override the rouing.yml loading mechanism to do what I want?


Solution

  • Every application can have only one routing.yml (of course it can be overrided by other plugins).

    The reason for this is quite simple: If you want to use multiple routing files (say routing1.yml and routing2.yml), and they both have a route called route1, which redirects to controller1/action and controller2/action respectively. Maybe you would be able to switch it in the view, and go to controller1/action in the one case and controller2/action in the other. But then: when a new request arrives, and the front controller is determining which controller / action to execute: how does it now which routing.yml to use?

    So I don't know exactly what you're trying to achieve, but I would go for two routes in your routing.yml, and select the route based on your view parameters.