Set Different Layout for Different Module in Zend Framework 2?

这一生的挚爱 提交于 2019-12-03 17:23:58

Usage

Using EdpModuleLayouts is very, very simple. In any module config or autoloaded config file simply specify the following:

array(
    'module_layouts' => array(
        'Teacher' => 'layout/teacher',
        'Student' => 'layout/student'
    ),
);

That's it! Of course you need to define those layouts, too... just check Application Modules module.config.php to see how to define a layout.

kilop

If you only want to change layout for your one action you can use layout() plugin in your controllers action, or if you want different layout for all actions in one controller only in your module you can do it in bootstrap:

public function onBootstrap(\Zend\EventManager\EventInterface $e) {
    $eventManager = $e->getApplication()->getEventManager();
    $sharedEventManager = $eventManager->getSharedManager();
    $sharedEventManager->attach('Auth\Controller\AuthController', \Zend\Mvc\MvcEvent::EVENT_DISPATCH, array($this, 'onDispatch'));
}

public function onDispatch(MvcEvent $e) {
    $controller = $e->getTarget();      
    $controller->layout('layout/loginLayout');
}

After each action in that controller you will change root ViewModel layout you can go further and specify here more controllers where you want your layout like this

$sharedEventManager>attach(array('Auth\Controller\AuthController',
'Auth\Controller\Registration'),
\Zend\Mvc\MvcEvent::EVENT_DISPATCH, array($this, 'onDispatch'));
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!