ZF2 different layouts in modules
To enable a different layout in a module, to your module.php for the module define a new layout like so
public function init(ModuleManager $mm) { $mm->getEventManager()->getSharedManager()->attach(__NAMESPACE__, 'dispatch', function($e) { $e->getTarget()->layout('admin/layout'); }); } |
then within your module.config.php view_manager settings define the template
'view_manager' => array( 'template_map' => array( 'admin/layout' => __DIR__ . '/../view/layout/cms.phtml', ), 'template_path_stack' => array( __DIR__ . '/../view', ), ), |
or you can define a direct path in your module.php without any template mapping i.e
public function init(ModuleManager $mm) { $mm->getEventManager()->getSharedManager()->attach(__NAMESPACE__, 'dispatch', function($e) { $e->getTarget()->layout('layout/admin'); }); } |
This will load module/view/layout/admin.phtml when this module is run
16,435 views
This entry was posted on Tuesday, June 4th, 2013 at 4:52 pm and is filed under Php, ZF2. You can follow any responses to this entry through the RSS 2.0 feed.
Thanks a lot!
Pretty clear.
It works, but why the URL from function $this->url() at layout still relative to other module?
Check your routing 🙂
it gives me an error?
Argument 1 passed to Login\Module::init() must be an instance of Login\ModuleManager, instance of Zend\ModuleManager\ModuleManager given, called in C:\xampp\htdocs\mvczend\vendor\zendframework\zendframework\library\Zend\ModuleManager\Listener\InitTrigger.php on line 33 and defined
Thanks a lot !! Easy one and Working fine.