5

Symfony2 で単一のルートをオーバーライドするにはどうすればよいですか?

ファイルが付属するバンドルがありbundle_routing.ymlます。
この親バンドルを拡張するバンドルには、ルーティング ファイルもあります 。ファイルの名前が異なることに注意してください。 routing.xml

このルーティング ファイルでは、1 つの親ルートをオーバーライドします。
簡単に再宣言してパターンを変更しようとしました。
しかし、それは適用されません。

親:

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 に答える