Php Zend Framework 2:使用多个模块的多个路由
我在zend framework 2应用程序中使用了两个模块:Php Zend Framework 2:使用多个模块的多个路由,php,configuration,module,routing,zend-framework2,Php,Configuration,Module,Routing,Zend Framework2,我在zend framework 2应用程序中使用了两个模块: 模块A 模块B 我遇到的问题是,我只能使用我为相应模块配置的一条路由。使用的路由取决于application.config.php文件中模块的排序: <?php return array( 'modules' => array( 'ModuleA','ModuleB' ); ?> 只需添加'priority'参数 <?php return array( 'rout
- 模块A
- 模块B
<?php
return array(
'modules' => array(
'ModuleA','ModuleB'
);
?>
只需添加'priority'参数
<?php
return array(
'router' => array(
'routes' => array(
'ModuleA' => array(
'type' => 'Literal',
'priority' => 100, // <-- priority
'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'
)
)
)
)
)
)
)
);
您是否也在moduleB配置中使用“控制器”=>“索引”
如果是,则存在您的问题索引
位于alias上,并且只有1控制器可以具有该别名,换句话说,alias应该是唯一的,将应用程序而不仅仅是模块丢弃
为你的控制器定义一个唯一的名称(别名),你就没事了
在我的项目中,我只使用FQN,因此没有混淆(Namespace\Controller\ControllerName
)在路由配置中似乎存在某种模糊性。我们将需要查看两个模块的实际路由,以了解它是什么。路由应具有唯一的名称。如果一个模块应该覆盖另一个模块的配置,那么通常的最佳做法是仅通过更改模块加载顺序来实现。摆弄优先级可能会导致一些非常不希望的连锁效应。
<?php
return array(
'router' => array(
'routes' => array(
'ModuleA' => array(
'type' => 'Literal',
'priority' => 100, // <-- priority
'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'
)
)
)
)
)
)
)
);