From 394322f35d2747d8989bb2a4274bc31b535cf8b9 Mon Sep 17 00:00:00 2001 From: the_undefined Date: Fri, 29 Feb 2008 20:22:57 +0000 Subject: [PATCH] Added pass feature to Router::connect Implemented it for Router::mapResources git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6489 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/router.php | 12 ++++++++++-- cake/tests/cases/libs/router.test.php | 12 ++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cake/libs/router.php b/cake/libs/router.php index f2621fb1d..ee3f386aa 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -274,7 +274,7 @@ class Router extends Object { Router::connect( "{$prefix}{$urlName}{$id}", array('controller' => $urlName, 'action' => $action, '[method]' => $params['method']), - array('id' => $options['id']) + array('id' => $options['id'], 'pass' => array('id')) ); } $this->__resourceMapped[] = $urlName; @@ -360,7 +360,7 @@ class Router extends Object { foreach ($_this->routes as $route) { if (($r = $_this->matchRoute($route, $url)) !== false) { $_this->__currentRoute[] = $route; - list($route, $regexp, $names, $defaults) = $route; + list($route, $regexp, $names, $defaults, $params) = $route; // remove the first element, which is the url array_shift($r); @@ -390,6 +390,14 @@ class Router extends Object { $out['named'] = $named; } } + + if (isset($params['pass'])) { + foreach ($params['pass'] as $param) { + if (isset($out[$param])) { + array_unshift($out['pass'], $out[$param]); + } + } + } break; } } diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index 93bf5164f..21eb64728 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -101,7 +101,7 @@ class RouterTest extends UnitTestCase { $_SERVER['REQUEST_METHOD'] = 'GET'; $result = $this->router->parse('/posts/13'); - $this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'view', 'id' => '13', '[method]' => 'GET')); + $this->assertEqual($result, array('pass' => array('13'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'view', 'id' => '13', '[method]' => 'GET')); $_SERVER['REQUEST_METHOD'] = 'POST'; $result = $this->router->parse('/posts'); @@ -109,14 +109,14 @@ class RouterTest extends UnitTestCase { $_SERVER['REQUEST_METHOD'] = 'PUT'; $result = $this->router->parse('/posts/13'); - $this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => '13', '[method]' => 'PUT')); + $this->assertEqual($result, array('pass' => array('13'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => '13', '[method]' => 'PUT')); $result = $this->router->parse('/posts/475acc39-a328-44d3-95fb-015000000000'); - $this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => '475acc39-a328-44d3-95fb-015000000000', '[method]' => 'PUT')); + $this->assertEqual($result, array('pass' => array('475acc39-a328-44d3-95fb-015000000000'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => '475acc39-a328-44d3-95fb-015000000000', '[method]' => 'PUT')); $_SERVER['REQUEST_METHOD'] = 'DELETE'; $result = $this->router->parse('/posts/13'); - $this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'delete', 'id' => '13', '[method]' => 'DELETE')); + $this->assertEqual($result, array('pass' => array('13'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'delete', 'id' => '13', '[method]' => 'DELETE')); $_SERVER['REQUEST_METHOD'] = 'GET'; $result = $this->router->parse('/posts/add'); @@ -127,11 +127,11 @@ class RouterTest extends UnitTestCase { $_SERVER['REQUEST_METHOD'] = 'GET'; $result = $this->router->parse('/posts/add'); - $this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'view', 'id' => 'add', '[method]' => 'GET')); + $this->assertEqual($result, array('pass' => array('add'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'view', 'id' => 'add', '[method]' => 'GET')); $_SERVER['REQUEST_METHOD'] = 'PUT'; $result = $this->router->parse('/posts/name'); - $this->assertEqual($result, array('pass' => array(), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => 'name', '[method]' => 'PUT')); + $this->assertEqual($result, array('pass' => array('name'), 'named' => array(), 'plugin' => '', 'controller' => 'posts', 'action' => 'edit', 'id' => 'name', '[method]' => 'PUT')); } function testUrlNormalization() {