Skip to content

Instantly share code, notes, and snippets.

@JiNexus
Last active June 17, 2016 06:07
Show Gist options
  • Save JiNexus/2af148e40b1afeb7223432d37e26ae35 to your computer and use it in GitHub Desktop.
Save JiNexus/2af148e40b1afeb7223432d37e26ae35 to your computer and use it in GitHub Desktop.
Create layout for each module in ZF2
<?php
return array(
// ...
'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(
'anothermodule/layout' => __DIR__ . '/../view/layout/layout.phtml',
'anothermodule/index/index' => __DIR__ . '/../view/anothermodule/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
'anothermodule' => __DIR__ . '/../view',
),
),
// ...
);
<?php
namespace AnotherModule;
// ...
use Zend\ModuleManager\ModuleManager;
// ...
class Module
{
// ...
public function init(ModuleManager $moduleManager)
{
$$moduleManager->getEventManager()->getSharedManager()->attach(__NAMESPACE__, 'dispatch', function($e) {
$e->getTarget()->layout('anothermodule/layout');
});
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment