【发布时间】:2014-03-08 14:57:21
【问题描述】:
我的项目有一个子域 shop.example.com 和 routing.yml 正在使用主机匹配功能(需要 Symfony >=2.2),如 here 所述:
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>
当我从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
但是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。我该如何解决这个问题?
【问题讨论】:
标签: symfony routing symfony-2.3 symfony-routing