Issues

ZF-9800: Modules names cannot be hyphenated like controller and action names

Description

Based on the convention for translating URI paths to module/controller/action the following URI should work:

/foo-bar/index/index

However, this fails to route to the fooBar module and instead routes to the default module (if one is set). This is because internally the formatModuleName method of the Zend_Controller_Dispatcher_Standard class is not being used consistently.

A patch to rectify this behaviour is included below:

==== /library/Zend/Controller/Action/Helper/ViewRenderer.php ====
225,226c225,229
<         $request = $this->getRequest();
<         $module  = $request->getModuleName();
---
>         $request    = $this->getRequest();
>         $dispatcher = $this->getFrontController()->getDispatcher();
>         $module     = $dispatcher->formatModuleName($request->getModuleName());
>         $module[0]  = strtolower($module[0]);
>         
228c231
<             $module = $this->getFrontController()->getDispatcher()->getDefaultModule();
---
>             $module = $dispatcher->getDefaultModule();
==== /library/Zend/Controller/Dispatcher/Standard.php ====
376a377,378
>             $module              = $this->formatModuleName($module);
>             $module[0]           = strtolower($module[0]);
402a405
>         $module        = $this->formatModuleName($module);

Comments

Confirmed in 1.11.2, also.

Here's a unified diff based on revision 23686:


Index: library/Zend/Controller/Action/Helper/ViewRenderer.php
===================================================================
--- library/Zend/Controller/Action/Helper/ViewRenderer.php  (revision 23686)
+++ library/Zend/Controller/Action/Helper/ViewRenderer.php  (working copy)
@@ -223,9 +223,11 @@
     public function getModule()
     {
         $request = $this->getRequest();
-        $module  = $request->getModuleName();
+        $dispatcher = $this->getFrontController()->getDispatcher();
+        $module = $dispatcher->formatModuleName($request->getModuleName());
+        $module[0] = strtolower($module[0]);
         if (null === $module) {
-            $module = $this->getFrontController()->getDispatcher()->getDefaultModule();
+            $module = $dispatcher->getDefaultModule();
         }
 
         return $module;
Index: library/Zend/Controller/Dispatcher/Standard.php
===================================================================
--- library/Zend/Controller/Dispatcher/Standard.php (revision 23686)
+++ library/Zend/Controller/Dispatcher/Standard.php (working copy)
@@ -378,7 +378,8 @@
         $className = $this->formatControllerName($controllerName);
 
         $controllerDirs      = $this->getControllerDirectory();
-        $module = $request->getModuleName();
+        $module = $this->formatModuleName($request->getModuleName());
+        $module[0] = strtolower($module[0]);
         if ($this->isValidModule($module)) {
             $this->_curModule    = $module;
             $this->_curDirectory = $controllerDirs[$module];
@@ -406,7 +407,7 @@
             return false;
         }
 
-        $module        = strtolower($module);
+        $module        = strtolower($this->formatModuleName($module));
         $controllerDir = $this->getControllerDirectory();
         foreach (array_keys($controllerDir) as $moduleName) {
             if ($module == strtolower($moduleName)) {

Are there any BC implications with changing this now? It would be nice to have consistency in module/controller/action formatting, but I fear that there may be implementations which rely on the current behaviour and this change would break the routing to those modules.

Attached a patch implementing the fix + unit test

Fixed in trunk (1.12.0): r24861