mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 10:36:16 +00:00
Added persist feature to routing, allows namedArgs to be auto-populated for reverse routing based on current request
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6704 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
296e8989ba
commit
ee94d5662c
2 changed files with 41 additions and 0 deletions
|
@ -755,11 +755,16 @@ class Router extends Object {
|
|||
$match = false;
|
||||
|
||||
foreach ($_this->routes as $route) {
|
||||
$originalUrl = $url;
|
||||
if (isset($route[4]['persist'], $_this->__params[0])) {
|
||||
$url = am(array_intersect_key($params, Set::combine($route[4]['persist'], '/')), $url);
|
||||
}
|
||||
if ($match = $_this->mapRouteElements($route, $url)) {
|
||||
$output = trim($match, '/');
|
||||
$url = array();
|
||||
break;
|
||||
}
|
||||
$url = $originalUrl;
|
||||
}
|
||||
$named = $args = array();
|
||||
$skip = array('bare', 'action', 'controller', 'plugin', 'ext', '?', '#', 'prefix', $admin);
|
||||
|
|
|
@ -671,6 +671,42 @@ class RouterTest extends UnitTestCase {
|
|||
$result = $this->router->parse('/posts/view/foo:bar/routing:fun/answer:42');
|
||||
$expected = array('pass' => array('routing:fun'), 'named' => array('foo' => 'bar', 'answer' => '42'), 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->router->reload();
|
||||
$this->router->connect('/posts/view/*', array('controller' => 'posts', 'action' => 'view'), array('named' => array('foo', 'answer')));
|
||||
$result = $this->router->parse('/posts/view/foo:bar/routing:fun/answer:42');
|
||||
$expected = array('pass' => array('routing:fun'), 'named' => array('foo' => 'bar', 'answer' => '42'), 'plugin' => null, 'controller' => 'posts', 'action' => 'view');
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->router->reload();
|
||||
$this->router->connect('/:lang/:color/posts/view/*', array('controller' => 'posts', 'action' => 'view'), array('persist' => array('lang', 'color')));
|
||||
$this->router->connect('/:lang/:color/posts/index', array('controller' => 'posts', 'action' => 'index'), array('persist' => array('lang')));
|
||||
$this->router->connect('/:lang/:color/posts/edit/*', array('controller' => 'posts', 'action' => 'index'));
|
||||
$this->router->connect('/about', array('controller' => 'pages', 'action' => 'view', 'about'));
|
||||
$this->router->parse('/en/red/posts/view/5');
|
||||
$this->router->setRequestInfo(array(
|
||||
array('controller' => 'posts', 'action' => 'view', 'lang' => 'en', 'color' => 'red', 'form' => array(), 'url' => array(), 'plugin' => null),
|
||||
array('base' => '/', 'here' => '/en/red/posts/view/5', 'webroot' => '/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array())
|
||||
));
|
||||
$expected = '/en/red/posts/view/6';
|
||||
$result = $this->router->url(array('controller' => 'posts', 'action' => 'view', 6));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$expected = '/en/blue/posts/index';
|
||||
$result = $this->router->url(array('controller' => 'posts', 'action' => 'index', 'color' => 'blue'));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$expected = '/posts';
|
||||
$result = $this->router->url(array('controller' => 'posts', 'action' => 'index'));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$expected = '/posts/edit/7';
|
||||
$result = $this->router->url(array('controller' => 'posts', 'action' => 'edit', 7));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$expected = '/about';
|
||||
$result = $this->router->url(array('controller' => 'pages', 'action' => 'view', 'about'));
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testUuidRoutes() {
|
||||
|
|
Loading…
Add table
Reference in a new issue