Search code examples
routessymfony1symfony-1.4yaml

Changing Symfony Default Route Class


In symfony's routing.yml, you can assign a different class to be used in place of sfRoute. i.e.

routeName:
 url: /url/blah
 class: sfRequestRoute
 param: {module: mymod, action: myaction}
 requirements:
   sf_method: [get]

However, I would like to be able to change the default class so that all routes use sfRequestRoute unless I specify otherwise. Is there a way to do this? I am using Symfony 1.4


Solution

  • Not exactly in the way you want. Something like that were it available would be found in config/factories.yml. But in this case the default is hardcoded into sfRoutingConfigHandler. You could attempt to override that but it seems liek a lot of work for a simple nicety. Instead i would jsut use a YAML reference:

    routeName:
     url: /url/blah
     class: &defRouteClass 'sfRequestRoute'
     param: {module: mymod, action: myaction}
     requirements:
       sf_method: [get]
    
    anotherRouteName:
      url: /url/blah2
      class: *defRouteClass
      param: {module: mymod, action: myotheraction}