0

私のプロジェクトにはサブドメインがshop.example.comありrouting.yml、ホスト マッチング機能を使用しています (Symfony >=2.2 が必要です) 。

example_shop:
    resource: "@MyShopBundle/Controller/"
    type:     annotation
    prefix:   /
    host:     "shop.example.com"

example_front:
    resource: "@MyFrontBundle/Controller/"
    type:     annotation
    prefix:   /

URLマッチングは問題なく動作しますが、フル URL/相対 URL の生成に問題があります (ドメインをサブドメインにリンクする、またはその逆):

<pre>shop_index:  {{ url('shop_index') }}</pre>
<pre>shop_test:   {{ path('shop_test') }}</pre>
<pre>front_index: {{ url('front_index') }}</pre>
<pre>front_test:  {{ url('front_test') }}</pre>

上記のコードをindex.html.twigof MyFrontBundle(route example.com) から実行すると:

shop_index:  http://shop.example.com/app_dev.php/
shop_test:   //shop.example.com/app_dev.php/test
front_index: http://example.com/app_dev.php/
front_test:  http://example.com/app_dev.php/test

index.html.twigただし、 of MyShopBundle(route )の同じコードは以下をshop.example.com生成します。

shop_index:  http://shop.example.com/app_dev.php/
shop_test:   /app_dev.php/test
front_index: http://shop.example.com/app_dev.php/     <!-- wrong! -->
front_test:  http://shop.example.com/app_dev.php/test <!-- wrong! -->

ご覧のとおり、問題はサブドメインからドメインの完全または相対 URL への URL を生成することです。どうすればこれを解決できますか?

4

1 に答える 1

1

フロント ルートはショップ ルートのようにドメインに固定されていないため、urlすべてのドメインがこのルートに一致するため、関数は現在のドメインを使用します。フロントエンド ルートを修正してみてください。

example_front:
    resource: "@MyFrontBundle/Controller/"
    type:     annotation
    prefix:   /
    host:     "example.com"
于 2014-03-08T16:17:34.717 に答える