diff --git a/cake/libs/router.php b/cake/libs/router.php index a38920f0d..7703010c8 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -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]]); } } } diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index c8c01c301..b2f54c18e 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -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'))); } } + ?> \ No newline at end of file