私のプロジェクトにはサブドメインが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.twig
of 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 を生成することです。どうすればこれを解決できますか?