From e0535de01d0e3c3e4990ecbacbdd4d9e15f32311 Mon Sep 17 00:00:00 2001 From: emcode Date: Sat, 6 Apr 2013 15:28:33 +0300 Subject: [PATCH 1/2] Added support for more complex module names like "Example\ModuleName" --- Module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Module.php b/Module.php index 05e6230..d9a63f8 100644 --- a/Module.php +++ b/Module.php @@ -8,7 +8,7 @@ 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, '\\')); + $moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\Controller')); $config = $e->getApplication()->getServiceManager()->get('config'); if (isset($config['module_layouts'][$moduleNamespace])) { $controller->layout($config['module_layouts'][$moduleNamespace]); From e9d3cf19910ba2a3cc1091eb0519e45778608224 Mon Sep 17 00:00:00 2001 From: emcode Date: Wed, 28 Aug 2013 01:47:04 +0200 Subject: [PATCH 2/2] Changed the way of matching namespaces of Module and Controller - we do not rely on \\Controller subnamespace anymore - we have more freedom when specyfying module => layout mapping as only beginning of namespace have to match - remember to set most specific aliases as first, under module_layouts config key --- Module.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Module.php b/Module.php index 2cd7cc7..4227e71 100644 --- a/Module.php +++ b/Module.php @@ -6,13 +6,27 @@ class Module public function onBootstrap($e) { $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController', 'dispatch', function($e) { - $controller = $e->getTarget(); + + $controller = $e->getTarget(); $controllerClass = get_class($controller); - $moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\Controller')); - $config = $e->getApplication()->getServiceManager()->get('config'); - if (isset($config['module_layouts'][$moduleNamespace])) { - $controller->layout($config['module_layouts'][$moduleNamespace]); + $config = $e->getApplication()->getServiceManager()->get('config'); + + if (!isset($config['module_layouts'])) + { + return; + } + + $moduleLayouts = $config['module_layouts']; + + foreach($moduleLayouts as $moduleNamespace => $layoutName) + { + if (strpos($controllerClass, $moduleNamespace) === 0) + { + $controller->layout($layoutName); + break; + } } + }, 100); } }