forked from EvanDotPro/EdpModuleLayouts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.php
More file actions
35 lines (30 loc) · 1.28 KB
/
Module.php
File metadata and controls
35 lines (30 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace EdpModuleLayouts;
use Zend\Mvc\MvcEvent, Zend\Mvc\Application;
class Module
{
public function onBootstrap($e)
{
$config = $e->getApplication()->getServiceManager()->get('config');
$eventManager = $e->getApplication()->getEventManager();
$eventManager->attach(
MvcEvent::EVENT_DISPATCH_ERROR,
function(\Zend\Mvc\MvcEvent $e) use($config) {
if($e->getError() === Application::ERROR_ROUTER_NO_MATCH) {
if(isset($config['module_layouts']['NotFound'])){
$e->getViewModel()->setTemplate($config['module_layouts']['NotFound']);
}
}
},
100
);
$eventManager->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController', 'dispatch', function($e) use($config) {
$controller = $e->getTarget();
$controllerClass = get_class($controller);
$moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
if (isset($config['module_layouts'][$moduleNamespace])) {
$controller->layout($config['module_layouts'][$moduleNamespace]);
}
}, 100);
}
}