Making parsed parameters always show up at the beginning of 'pass', closes #4299

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6517 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-03-08 16:14:51 +00:00
parent 2e3391006f
commit 24ea731e7f
2 changed files with 13 additions and 10 deletions

View file

@ -206,11 +206,7 @@ class Router extends Object {
function connect($route, $default = array(), $params = array()) {
$_this =& Router::getInstance();
$admin = Configure::read('Routing.admin');
$default = array_merge(array('action' => null), $default);
if (!empty($default) && empty($default['action'])) {
$default['action'] = 'index';
}
$default = array_merge(array('action' => 'index'), $default);
if(isset($default[$admin])) {
$default['prefix'] = $admin;
@ -419,11 +415,11 @@ class Router extends Object {
$out['named'] = $named;
}
}
if (isset($params['pass'])) {
foreach ($params['pass'] as $param) {
if (isset($out[$param])) {
$out['pass'][] = $out[$param];
for ($i = count($params['pass']) - 1; $i > -1; $i--) {
if (isset($out[$params['pass'][$i]])) {
array_unshift($out['pass'], $out[$params['pass'][$i]]);
}
}
}

View file

@ -621,6 +621,12 @@ class RouterTest extends UnitTestCase {
$result = $this->router->parse('/posts/5:sample-post-title');
$expected = array('pass' => array('5', 'sample-post-title'), 'named' => array(), 'id' => 5, 'url_title' => 'sample-post-title', 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
$this->assertEqual($result, $expected);
$this->router->reload();
$this->router->connect('/posts/:id::url_title/*', array('controller' => 'posts', 'action' => 'view'), array('pass' => array('id', 'url_title'), 'id' => '[\d]+'));
$result = $this->router->parse('/posts/5:sample-post-title/other/params/4');
$expected = array('pass' => array('5', 'sample-post-title', 'other', 'params', '4'), 'named' => array(), 'id' => 5, 'url_title' => 'sample-post-title', 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
$this->assertEqual($result, $expected);
}
function testUuidRoutes() {
@ -938,7 +944,7 @@ class RouterTest extends UnitTestCase {
$result = $this->router->parse('/pages/display/home/parameter:value');
$expected = array('pass' => array('home'), 'named' => array('parameter' => 'value'), 'plugin' => null, 'controller' => 'pages', 'action' => 'display');
$this->assertEqual($result, $expected);
$this->router->reload();
$this->router->connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
$this->router->connect('/pages/*/:event', array('controller' => 'pages', 'action' => 'display'), array('event' => '[a-z0-9_-]+'));
@ -1092,4 +1098,5 @@ class RouterTest extends UnitTestCase {
$this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'index', '[method]' => array('GET', 'POST')));
}
}
?>