I am using EdpModuleLayouts to use one layout to mobile version of my zf2 webapp and another to the "desktop" version.
The configuration in module.config.php in Application module:
...'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(
'module_layouts' => array(
'Application' => 'layout/application',
'User' => 'layout/user',
),
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
Module.php of the Application module it's like this:
public function onBootstrap(MvcEvent $e)
{
$e->getApplication()->getServiceManager()->get('translator');
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
$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, '\\'));
$config = $e->getApplication()->getServiceManager()->get('config');
if (isset($config['module_layouts'][$moduleNamespace])) {
$controller->layout($config['module_layouts'][$moduleNamespace]);
echo $config['module_layouts'][$moduleNamespace];
}
}, 100);
}
Finally, I have one layout in Application module and another in User module. At this moment every time render the layout in the User Model, even though I enter the Application url.
I stucked on this, I appreciate some help.
module_layouts
should be a top-level entry. Check a couple of other Threads about this topic, there's like 10-20 of it ;) – Sam