I have two module in my ZF2 application, both module have different configuration for themself, and both module have different Module.php with different configruation inside it.
I have a login process for Admin, which is defined in Module.php like below: in onBootstrap funtion:
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);
}
boforeDispatch function which is called inside the onBootstrap
for login process check
function boforeDispatch(MvcEvent $event) {
......
//did something
......
}
Whenever I am going to run Front module, Admin module's function beforeDispatch is running. I also tried to define another function inside Front module with no content inside so that it could not merge it.
2
I have written different 404 template for both module, but Front's template is running. Here is the code.:
'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',
),
),
both's files are inside its module folder with same structure. Q: How to prevent merging one module configuration from another?