From a2c209a284a00d728161d74c00a684907dc87614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Carneiro?= Date: Wed, 20 Aug 2014 18:15:53 -0300 Subject: [PATCH 1/3] search for the sub namespace in module name still needs an update to make it properly work when: /namespace/subnamespace1/subnamespace2/ /namespace/subnamespace1/ since both would return "true" in strpos --- Module.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Module.php b/Module.php index 019a842..5053baa 100644 --- a/Module.php +++ b/Module.php @@ -8,10 +8,11 @@ public function onBootstrap($e) $e->getApplication()->getEventManager()->getSharedManager()->attach('Zend\Mvc\Controller\AbstractController', 'dispatch', function($e) { $controller = $e->getTarget(); $controllerClass = get_class($controller); - $moduleNamespace = substr($controllerClass, 0, strpos($controllerClass, '\\')); $config = $e->getApplication()->getServiceManager()->get('config'); - if (isset($config['module_layouts'][$moduleNamespace])) { - $controller->layout($config['module_layouts'][$moduleNamespace]); + foreach($config['module_layouts'] as $module_namespace => $layout){ + if(strpos($controllerClass, $module_namespace)){ + $controller->layout($layout); + } } }, 100); } From e5edf8d21aa855919d2fde8cae4e97fb1dcb897a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Carneiro?= Date: Wed, 20 Aug 2014 18:22:25 -0300 Subject: [PATCH 2/3] update if condition --- Module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Module.php b/Module.php index 5053baa..f0b7d5e 100644 --- a/Module.php +++ b/Module.php @@ -10,7 +10,7 @@ public function onBootstrap($e) $controllerClass = get_class($controller); $config = $e->getApplication()->getServiceManager()->get('config'); foreach($config['module_layouts'] as $module_namespace => $layout){ - if(strpos($controllerClass, $module_namespace)){ + if(false !== strpos($controllerClass, $module_namespace)){ $controller->layout($layout); } } From 5f0e45c72665ba20e52aba238200277e0cbb18e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Carneiro?= Date: Wed, 20 Aug 2014 18:26:40 -0300 Subject: [PATCH 3/3] fix if condition otherwise it would find the name in any place, including the controller name --- Module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Module.php b/Module.php index f0b7d5e..8917670 100644 --- a/Module.php +++ b/Module.php @@ -10,7 +10,7 @@ public function onBootstrap($e) $controllerClass = get_class($controller); $config = $e->getApplication()->getServiceManager()->get('config'); foreach($config['module_layouts'] as $module_namespace => $layout){ - if(false !== strpos($controllerClass, $module_namespace)){ + if(false !== strpos($controllerClass, $module_namespace."\\")){ $controller->layout($layout); } }