I have this is problem. In my ZF2 application I manage login system with byjauthorize and zfcuser, and I have two different base layout. One dedicated to the login page and one dedicated to the application when the user is logged in. This is code in Application module in module.config.php:
'template_map' => array(
'layout/login_layout' => __DIR__ . '/../view/layout/login_layout.phtml',
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
Now always Application module in Module.php, i set this code:
public function onBootstrap(MvcEvent $e)
{
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$application = $e->getTarget();
// Change default layout if user is logged
$sm = $application->getServiceManager();
$auth = $sm->get('zfcuser_auth_service');
if ($auth->hasIdentity()) {
$eventManager->attach("dispatch", function($e) {
$controller = $e->getTarget();
$s_matchedRoute = $e->getParam('route-match')->getMatchedRouteName();
if ($s_matchedRoute === 'zfcuser/login') {
$controller->layout('layout/login_layout');
} else {
$controller->layout('layout/layout');
}
});
/*
* Check Admin ACL with BjyAuthorize:
* use RedirectionStrategy (that redirects to ZfcUser's login route by default)
*/
$strategy = new RedirectionStrategy();
$strategy->setRedirectRoute('application/error');
$e->getTarget()->getEventManager()->attach($strategy);
} else {
$eventManager->attach("dispatch", function($e) {
$controller = $e->getTarget();
$controller->layout('layout/login_layout');
});
$strategy = new RedirectionStrategy();
$strategy->setRedirectRoute('zfcuser/login');
$e->getTarget()->getEventManager()->attach($strategy);
}
/**
* Format style login page
*/
$this->layoutFormLogin($eventManager);
// Setting function to handler error
set_error_handler(array('Application\Module','handlePhpErrors'));
}
But when $auth->hasIdentity is false RedirectionStrategy not redirect the route in zfcuser/login. Where misake ? p.s my application.config.php is this:
// 3rd part modules
'DoctrineModule',
'DoctrineORMModule',
'ZendDeveloperTools',
'ZfcBase',
'ZfcUser',
'ZfcUserDoctrineORM',
'BjyAuthorize',
'DOMPDFModule',
'WebinoImageThumb',
//My Module
'Application',