Set a generic layout for all modules in Zend framework 2

放肆的年华 提交于 2019-11-30 17:04:44

You can set the layout to be what ever you want in each modules config, just change the layout to be what ever you want:

module.config.php or inside getConfig()

'view_manager' => array(
    // other stuff here.. 
    'template_map' => array(
        // use Applications layout instead
        'layout/layout' => __DIR__ . '/../Application/view/application/layout/layout.phtml',
    ),
    'template_path_stack' => array(
        __DIR__ . '/../view',
    ),
),

Or you can set each module to selectively set it's layout in Module.php:

Module.php

/**
 * Initialize
 */
public function init(ModuleManager $manager)
{
    $events = $manager->getEventManager();
    $sharedEvents = $events->getSharedManager();
    $sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) {
        /* @var $e \Zend\Mvc\MvcEvent */
        // fired when an ActionController under the namespace is dispatched.
        $controller = $e->getTarget();
        $routeMatch = $e->getRouteMatch();
        /* @var $routeMatch \Zend\Mvc\Router\RouteMatch */
        $routeName = $routeMatch->getMatchedRouteName();
        $controller->layout('application/layout/layout');
    }, 100);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!