【发布时间】:2014-04-03 12:40:00
【问题描述】:
我在我的 zend 框架 2 应用程序中使用了两个模块:
- 模块 A
- 模块 B
我遇到的问题是我只能使用我为相应模块配置的一个路由。使用的路由取决于 application.config.php 文件中模块的排序:
<?php
return array(
'modules' => array(
'ModuleA','ModuleB'
);
?>
每个模块都包含几乎相同的配置module.config.php:
<?php
return array(
'router' => array(
'routes' => array(
'ModuleA' => array(
'type' => 'Literal',
'options' => array(
'route' => '/moduleA',
'defaults' => array(
'__NAMESPACE__' => 'ModuleA\Controller',
'controller' => 'index',
'action' => 'index',
),
),
'may_terminate' => false,
'child_routes' => array(
'moduleA-index' => array(
'type' => 'Segment',
'options' => array(
'route' => '/index[/:action]',
'defaults' => array(
'controller' => 'index',
'action' => 'index'
)
)
)
)
)
)
)
);
目前情况:
- URL /moduleA 路由到 /ModuleA/Index/Index
- URL /moduleB 路由到 /ModuleA/Index/Index
预期:
- URL /moduleA 路由到 /ModuleA/Index/Index
- URL /moduleB 路由到 /ModuleB/Index/Index
您对我如何以正确的方式使用这两种配置/路由有什么建议吗?
【问题讨论】:
-
您的路由配置中似乎存在某种歧义。我们将需要查看两个模块的实际路线以了解它是什么。
-
路由应该有唯一的名字。如果一个模块应该覆盖另一个模块的配置,一个常见的最佳实践是只通过更改模块加载顺序来做到这一点。摆弄优先级可能会导致一些非常不受欢迎的连锁效应。
标签: php configuration module routing zend-framework2