ソースを参照

ZF-6025: allow using alternate keys for mod/con/act

- Don't use hard-coded keys, but those specified in the object

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23939 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 14 年 前
コミット
72a785f930

+ 3 - 3
library/Zend/Controller/Action/Helper/Redirector.php

@@ -294,9 +294,9 @@ class Zend_Controller_Action_Helper_Redirector extends Zend_Controller_Action_He
             }
         }
 
-        $params['module']     = $module;
-        $params['controller'] = $controller;
-        $params['action']     = $action;
+        $params[$request->getModuleKey()]     = $module;
+        $params[$request->getControllerKey()] = $controller;
+        $params[$request->getActionKey()]     = $action;
 
         $router = $this->getFrontController()->getRouter();
         $url    = $router->assemble($params, 'default', true);

+ 22 - 0
tests/Zend/Controller/Action/Helper/RedirectorTest.php

@@ -533,6 +533,28 @@ class Zend_Controller_Action_Helper_RedirectorTest extends PHPUnit_Framework_Tes
         $this->assertEquals($expected, $result);
     }
 
+    /** @group ZF-6025 */
+    public function testGotoSimpleShouldNotHardcodeControllerActionModuleKeys()
+    {
+        $this->request->setControllerKey('foo')
+                      ->setActionKey('bar')
+                      ->setModuleKey('baz');
+
+        $this->router->removeRoute('default');
+        $this->router->addRoute('default', new Zend_Controller_Router_Route(
+            ':baz/:foo/:bar/*', array(
+                'baz' => 'default',
+                'foo' => 'index',
+                'bar' => 'index'
+            )
+        ));
+
+        $this->redirector->gotoSimple('babar', 'barbapapa', 'barbazoo', array('asd' => 1));
+        $result = $this->redirector->getRedirectUrl();
+        $expected = '/barbazoo/barbapapa/babar/asd/1';
+        $this->assertEquals($expected, $result);
+    }
+
     /**#@-*/
 
     protected function _parseLocationHeaderValue()