【发布时间】:2015-12-28 07:58:41
【问题描述】:
我的 ZF2 应用程序中有两个模块,两个模块都有不同的配置,两个模块都有不同的 Module.php,里面有不同的配置。
我有一个 Admin 的登录过程,它在 Module.php 中定义,如下所示: 在 onBootstrap 函数中:
public function onBootstrap($e) {
$e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) {
$controller = $e->getTarget();
$controllerClass = get_class($controller);
$moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
if ('Admin' === $moduleNamespace) {
$controller->layout('layout/admin');
}
}, 100);
$application = $e->getApplication();
$eventManager = $application->getEventManager();
..........
..........
$eventManager->attach(MvcEvent::EVENT_DISPATCH, array($this, 'boforeDispatch'), 100);
}
在onBootstrap内部调用的boforeDispatch函数用于登录过程检查
function boforeDispatch(MvcEvent $event) {
......
//did something
......
}
每当我要运行 Front 模块时,Admin 模块的 beforeDispatch 功能就会运行。我还尝试在 Front 模块中定义另一个没有内容的函数,使其无法合并。
2
我为这两个模块编写了不同的 404 模板,但 Front 的模板正在运行。代码如下:
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/front' => __DIR__ . '/../view/layout/layout.phtml',
'front/index/index' => __DIR__ . '/../view/front/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
这两个文件都在其模块文件夹中,具有相同的结构。 问:如何防止一个模块配置与另一个模块配置合并?
【问题讨论】:
标签: php zend-framework zend-framework2 zend-config