Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override single route in Symfony2

Tags:

routes

symfony

How can I override a single route in Symfony2?

I have a bundle that comes with a bundle_routing.yml file.
In a bundle that extends this parent bundle i also have routing file: routing.xml
Note that the files are named different.

In this routing file I like to override a single parent route.
I tried to simple redeclare it and change the pattern.
But it's not applied.

parent:

MyParentBundle_detailpage:
    pattern:  /detail
    defaults: { _controller: "MyParentBundle:Item:detail" }

child:

<route id="MyParentBundle_detailpage" pattern="/itemDetails">
        <default key="_controller">MyParentBundle:Item:detail</default>
</route>
like image 445
ivoba Avatar asked Nov 07 '12 13:11

ivoba


1 Answers

Found the reason myself: Its because of the import order in the main routing file.

app/config/routing.yml

The parent routing must be imported first and the routing of the child bundle must be imported second.

MyParentBundle:
    resource: "@MyParentBundle/Resources/config/bundle_routing.yml"
    prefix:   /
MyChildBundle:
    resource: "@MyChildBundle/Resources/config/routing.xml"
    prefix:   /
like image 167
ivoba Avatar answered Sep 28 '22 17:09

ivoba