diff --git a/cake/libs/router.php b/cake/libs/router.php index 8a55b488c..5f6dccadb 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -770,9 +770,6 @@ class Router { } else { $params = end($self->__params); } - if (isset($params['prefix']) && strpos($params['action'], $params['prefix']) === 0) { - $params['action'] = substr($params['action'], strlen($params['prefix']) + 1); - } } $path = array('base' => null); @@ -818,6 +815,9 @@ class Router { } elseif (isset($url[$prefix]) && !$url[$prefix]) { unset($url[$prefix]); } + if (isset($url[$prefix]) && strpos($url['action'], $prefix) === 0) { + $url['action'] = substr($url['action'], strlen($prefix) + 1); + } } $url += array('controller' => $params['controller'], 'plugin' => $params['plugin']); diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index c7549da5e..a68b83a88 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -1741,7 +1741,7 @@ class RouterTest extends CakeTestCase { Router::setRequestInfo(array( array('controller' => 'users', 'action' => 'login', 'company' => true, 'form' => array(), 'url' => array(), 'plugin' => null), - array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array()) + array('base' => '/', 'here' => '/', 'webroot' => '/base/') )); $result = Router::url(array('controller' => 'users', 'action' => 'login', 'company' => false)); @@ -1749,6 +1749,32 @@ class RouterTest extends CakeTestCase { $this->assertEqual($result, $expected); } +/** + * test url generation with prefixes and custom routes + * + * @return void + */ + function testUrlWritingWithPrefixesAndCustomRoutes() { + Router::connect( + '/admin/login', + array('controller' => 'users', 'action' => 'login', 'prefix' => 'admin', 'admin' => true) + ); + Router::setRequestInfo(array( + array('controller' => 'posts', 'action' => 'index', 'admin' => true, 'prefix' => 'admin', + 'form' => array(), 'url' => array(), 'plugin' => null + ), + array('base' => '/', 'here' => '/', 'webroot' => '/') + )); + $result = Router::url(array('controller' => 'users', 'action' => 'login', 'admin' => true)); + $this->assertEqual($result, '/admin/login'); + + $result = Router::url(array('controller' => 'users', 'action' => 'login')); + $this->assertEqual($result, '/admin/login'); + + $result = Router::url(array('controller' => 'users', 'action' => 'admin_login')); + $this->assertEqual($result, '/admin/login'); + } + /** * testPassedArgsOrder method *