Permalink
Browse files

Moving action modification when a prefix is detected so it affects al…

…l url arrays. Previously it was only applied to parameters in the current request. This Fixes inconsistencies between request parameters and url parameters.  Fixes #570
  • Loading branch information...
1 parent 42bc252 commit 404401b4de87fbd3cfde09d539b7d44c9c80e3da @markstory markstory committed Apr 12, 2010
Showing with 30 additions and 4 deletions.
  1. +3 −3 cake/libs/router.php
  2. +27 −1 cake/tests/cases/libs/router.test.php
View
@@ -770,9 +770,6 @@ function url($url = null, $full = false) {
} 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 @@ function url($url = null, $full = false) {
} 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']);
@@ -1741,7 +1741,7 @@ function testUrlWritingWithPrefixes() {
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));
@@ -1750,6 +1750,32 @@ function testUrlWritingWithPrefixes() {
}
/**
+ * 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
*
* @access public

0 comments on commit 404401b

Please sign in to comment.