【发布时间】:2013-02-07 16:17:53
【问题描述】:
我正在 Zend Framework 2 中编写一个应用程序,它将从几个不同的子域运行,并且我希望为每个子域设置一个不同的模块,以保持整洁。
我的问题是当我向路由添加多个子域时,它会丢失其中一个子域。
例如:此设置有效 testbed.localhost(模块/应用程序) a.testbed.localhost (模块/A)
如果我添加一个额外的,它会将所有对 a 的请求路由到应用程序索引控制器
例如 testbed.localhost (模块/应用), a.testbed.localhost (模块/A), b.testbed.localhost (模块/B)
这是module/A的module.config.php
'router' => array(
'routes' => array(
'ads' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'a.testbed.localhost',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'A\Controller',
'controller' => 'A\Controller\A',
'action' => 'index',
),
),
这是module/B中module.config.php中的路由
'router' => array(
'routes' => array(
'ads' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'b.testbed.localhost',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'B\Controller',
'controller' => 'B\Controller\B',
'action' => 'index',
),
),
现在两个 module.config.php 文件中的命名空间都是正确的,我注意到如果我从 config/application.config.php 中删除对它的引用,子域 a.testbed.localhost 将起作用
<?php
return array(
'modules' => array(
'Application',
'A',
'B', <--- A doesn't work if B is here
),
如果我在上面的模块数组中交换 A 和 B,那么 B 将被转发到应用程序模块并且 A 将工作。所以它似乎有超过 1 个子域的问题。有没有人有任何想法/遇到同样的事情?
【问题讨论】:
-
我认为这是因为您的路线名称相同。不妨试试 a-ads 和 b-ads 的路线名称,看看会发生什么。
-
你说得对,天哪,我不敢相信我没有发现这一点。昨天盯着那个看了几个小时!
-
你能关闭这个问题,让它不留在未回答的列表中吗?
-
@Diemuzi,你解决了我的问题。写下您的评论作为答案。
-
@deadtoy 你能关闭这个问题吗?
标签: subdomain url-routing zend-framework2