-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.php
More file actions
26 lines (21 loc) · 1.05 KB
/
Module.php
File metadata and controls
26 lines (21 loc) · 1.05 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
<?php
namespace EdpModuleLayouts;
class Module
{
public function onBootstrap($e)
{
$e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\Mvc\Controller\AbstractActionController', 'dispatch', function($e) {
$controller = $e->getTarget();
$controllerClass = get_class($controller);
$moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\'));
$config = $e->getApplication()->getServiceManager()->get('config');
$routeMatch = $e->getRouteMatch();
$actionName = strtolower($routeMatch->getParam('action', 'not-found')); // get the action name
if (isset($config['module_layouts'][$moduleNamespace][$actionName])) {
$controller->layout($config['module_layouts'][$moduleNamespace][$actionName]);
}elseif(isset($config['module_layouts'][$moduleNamespace]['default'])) {
$controller->layout($config['module_layouts'][$moduleNamespace]['default']);
}
}, 100);
}
}