我的项目有一个子域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 时遇到了一些麻烦(将域链接到子域,反之亦然):
<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>
当我从(route )运行上述代码index.html.twig
时:MyFrontBundle
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
但是(route ) 中index.html.twig
的相同代码会产生:MyShopBundle
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。我该如何解决这个问题?