mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Adding URL fragment (hash) support in Router::url() (Ticket #2432)
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4869 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
11c5e916b8
commit
3ba273b16d
2 changed files with 18 additions and 5 deletions
|
@ -443,7 +443,7 @@ class Router extends Object {
|
|||
}
|
||||
|
||||
$base = $_this->stripPlugin($path['base'], $params['plugin']);
|
||||
$extension = $output = $mapped = $q = null;
|
||||
$extension = $output = $mapped = $q = $frag = null;
|
||||
|
||||
if (is_array($url) && !empty($url)) {
|
||||
if (isset($url['full_base']) && $url['full_base'] == true) {
|
||||
|
@ -454,6 +454,10 @@ class Router extends Object {
|
|||
$q = $url['?'];
|
||||
unset($url['?']);
|
||||
}
|
||||
if (isset($url['#'])) {
|
||||
$frag = '#' . urlencode($url['#']);
|
||||
unset($url['#']);
|
||||
}
|
||||
if (!isset($url['action'])) {
|
||||
if (!isset($url['controller']) || $params['controller'] == $url['controller']) {
|
||||
$url['action'] = $params['action'];
|
||||
|
@ -486,7 +490,7 @@ class Router extends Object {
|
|||
}
|
||||
|
||||
$named = $args = array();
|
||||
$skip = am(array_keys($_this->__mapped), array('bare', 'action', 'controller', 'plugin', 'ext', '?'));
|
||||
$skip = am(array_keys($_this->__mapped), array('bare', 'action', 'controller', 'plugin', 'ext', '?', '#'));
|
||||
if(defined('CAKE_ADMIN')) {
|
||||
$skip[] = CAKE_ADMIN;
|
||||
}
|
||||
|
@ -558,7 +562,7 @@ class Router extends Object {
|
|||
if ($full) {
|
||||
$output = FULL_BASE_URL . $output;
|
||||
}
|
||||
return $output . $extension . $_this->queryString($q);
|
||||
return $output . $extension . $_this->queryString($q) . $frag;
|
||||
}
|
||||
/**
|
||||
* Maps a URL array onto a route and returns the string result, or false if no match
|
||||
|
|
|
@ -101,7 +101,6 @@ class RouterTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
function testUrlGeneration() {
|
||||
$this->router->reload();
|
||||
extract($this->router->getNamedExpressions());
|
||||
|
||||
$this->router->connect('/', array('controller'=>'pages', 'action'=>'display', 'home'));
|
||||
|
@ -146,6 +145,17 @@ class RouterTest extends UnitTestCase {
|
|||
$result = $this->router->url(array('controller' => 'posts', '0', '?' => 'var=test&var2=test2'));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->router->url(array('controller' => 'posts', '0', '?' => array('var' => 'test', 'var2' => 'test2')));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->router->url(array('controller' => 'posts', '0', '?' => 'var=test&var2=test2', '#' => 'unencoded string %'));
|
||||
$expected = '/posts/index/0?var=test&var2=test2#unencoded+string+%25';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testUrlParsing() {
|
||||
extract($this->router->getNamedExpressions());
|
||||
|
||||
$this->router->routes = array();
|
||||
$this->router->connect('/posts/:value/:somevalue/:othervalue/*', array('controller' => 'posts', 'action' => 'view'), array('value','somevalue', 'othervalue'));
|
||||
$result = $this->router->parse('/posts/2007/08/01/title-of-post-here');
|
||||
|
@ -175,7 +185,6 @@ class RouterTest extends UnitTestCase {
|
|||
$result = $this->router->parse('/posts/2007/08/01/title-of-post-here');
|
||||
$expected = array('year' => '2007', 'month' => '08', 'day' => '01', 'controller' => 'posts', 'action' => 'view', 'plugin' =>'', 'pass' => array('0' => 'title-of-post-here'));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
}
|
||||
|
||||
function testAdminRouting() {
|
||||
|
|
Loading…
Add table
Reference in a new issue