5

如何在 Symfony2 中覆盖单个路由?

我有一个附带bundle_routing.yml文件的捆绑包。
在扩展此父捆绑包的捆绑包中,我也有路由文件: 请注意,文件的名称不同。 routing.xml

在这个路由文件中,我喜欢覆盖单个父路由。
我试图简单地重新声明它并改变模式。
但它没有应用。

家长:

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

孩子:

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

1 回答 1

14

自己找到原因:是因为主路由文件中的导入顺序。

app/config/routing.yml

必须先导入父路由,然后必须导入子捆绑包的路由。

MyParentBundle:
    resource: "@MyParentBundle/Resources/config/bundle_routing.yml"
    prefix:   /
MyChildBundle:
    resource: "@MyChildBundle/Resources/config/routing.xml"
    prefix:   /
于 2012-11-07T13:33:44.267 回答