router
is an alias, not a service. To get this from ContainerBuilder
, use ContainerBuilder::getAlias
. To get the service identifier, you need to pass this object to the string: (string) $container->getAlias('router')
. Now you can use this identifier to get the service: $container->getDefinition($container->getAlias('router'))
. And then you get a Service that you can change to add routes.
By the way, I'm not sure if this is really what you want. How about using a CmfRoutingBundle . Then you use the Chain Router, so you can use both the Symfony2 router and DynamicRouter. DynamicRouter can be used with a custom route provider, in which you return the necessary routes (you can get them from any resource you need).
source share