覆盖Symfony2中的单个路由 [英] Override single route in Symfony2

查看:89
本文介绍了覆盖Symfony2中的单个路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Symfony2中覆盖一条路由?

How can I override a single route in Symfony2?

我有一个捆绑包,捆绑包带有 bundle_routing.yml code> 文件。

在扩展此父捆绑包的捆绑包中,我还具有路由文件:
routing.xml

请注意,文件的名称不同。

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.

父级:

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

子级:

<route id="MyParentBundle_detailpage" pattern="/itemDetails">
        <default key="_controller">MyParentBundle:Item:detail</default>
</route>


推荐答案

我自己找到原因:
其原因

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

这篇关于覆盖Symfony2中的单个路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆