Issues

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

Issue Type: Bug Created: 2010-05-04T11:56:36.000+0000 Last Updated: 2012-06-01T23:40:51.000+0000 Status: Resolved Fix version(s): - 1.12.0 (27/Aug/12)

Reporter: Geoff Nicol (gnicol) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Controller

  • FixForZF1.12
  • zf-caretaker-adamlundrigan
  • zf-crteam-review

Related issues: Attachments: - ZF-9800.patch

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:

<pre class="literal">
==== /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();



<pre class="literal">
==== /library/Zend/Controller/Dispatcher/Standard.php ====
376a377,378
>             $module              = $this->formatModuleName($module);
>             $module[0]           = strtolower($module[0]);
402a405
>         $module        = $this->formatModuleName($module);

Comments

Posted by Ryan Lange (ryan.lange) on 2011-01-31T10:17:43.000+0000

Confirmed in 1.11.2, also.

Posted by Ryan Lange (ryan.lange) on 2011-02-01T09:06:59.000+0000

Here's a unified diff based on revision 23686:

<pre class="highlight">
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)) {

Posted by Adam Lundrigan (adamlundrigan) on 2012-02-24T03:08:10.000+0000

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.

Posted by Adam Lundrigan (adamlundrigan) on 2012-06-01T16:16:22.000+0000

Attached a patch implementing the fix + unit test

Posted by Adam Lundrigan (adamlundrigan) on 2012-06-01T23:40:51.000+0000

Fixed in trunk (1.12.0): r24861

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts