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 时遇到了一些麻烦(将域链接到子域,反之亦然):

<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时:MyFrontBundleexample.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的相同代码会产生:MyShopBundleshop.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 回答