Override single route in Symfony2

…衆ロ難τιáo~ 提交于 2019-12-22 06:39:21

问题


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>

回答1:


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:   /


来源:https://stackoverflow.com/questions/13270484/override-single-route-in-symfony2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!