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
This commit is contained in:
the_undefined 2008-02-29 20:22:57 +00:00
parent 3d191461b2
commit 394322f35d
2 changed files with 16 additions and 8 deletions

View file

@ -274,7 +274,7 @@ class Router extends Object {
Router::connect( Router::connect(
"{$prefix}{$urlName}{$id}", "{$prefix}{$urlName}{$id}",
array('controller' => $urlName, 'action' => $action, '[method]' => $params['method']), array('controller' => $urlName, 'action' => $action, '[method]' => $params['method']),
array('id' => $options['id']) array('id' => $options['id'], 'pass' => array('id'))
); );
} }
$this->__resourceMapped[] = $urlName; $this->__resourceMapped[] = $urlName;
@ -360,7 +360,7 @@ class Router extends Object {
foreach ($_this->routes as $route) { foreach ($_this->routes as $route) {
if (($r = $_this->matchRoute($route, $url)) !== false) { if (($r = $_this->matchRoute($route, $url)) !== false) {
$_this->__currentRoute[] = $route; $_this->__currentRoute[] = $route;
list($route, $regexp, $names, $defaults) = $route; list($route, $regexp, $names, $defaults, $params) = $route;
// remove the first element, which is the url // remove the first element, which is the url
array_shift($r); array_shift($r);
@ -390,6 +390,14 @@ class Router extends Object {
$out['named'] = $named; $out['named'] = $named;
} }
} }
if (isset($params['pass'])) {
foreach ($params['pass'] as $param) {
if (isset($out[$param])) {
array_unshift($out['pass'], $out[$param]);
}
}
}
break; break;
} }
} }

View file

@ -101,7 +101,7 @@ class RouterTest extends UnitTestCase {
$_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_METHOD'] = 'GET';
$result = $this->router->parse('/posts/13'); $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'; $_SERVER['REQUEST_METHOD'] = 'POST';
$result = $this->router->parse('/posts'); $result = $this->router->parse('/posts');
@ -109,14 +109,14 @@ class RouterTest extends UnitTestCase {
$_SERVER['REQUEST_METHOD'] = 'PUT'; $_SERVER['REQUEST_METHOD'] = 'PUT';
$result = $this->router->parse('/posts/13'); $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'); $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'; $_SERVER['REQUEST_METHOD'] = 'DELETE';
$result = $this->router->parse('/posts/13'); $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'; $_SERVER['REQUEST_METHOD'] = 'GET';
$result = $this->router->parse('/posts/add'); $result = $this->router->parse('/posts/add');
@ -127,11 +127,11 @@ class RouterTest extends UnitTestCase {
$_SERVER['REQUEST_METHOD'] = 'GET'; $_SERVER['REQUEST_METHOD'] = 'GET';
$result = $this->router->parse('/posts/add'); $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'; $_SERVER['REQUEST_METHOD'] = 'PUT';
$result = $this->router->parse('/posts/name'); $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() { function testUrlNormalization() {