我的 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',
),
),
两者的文件都在其具有相同结构的模块文件夹中。问:如何防止将一个模块配置与另一个模块配置合并?