mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Moving action modification when a prefix is detected so it affects all url arrays. Previously it was only applied to parameters in the current request. This fixes inconsistencies between request parameters and url parameters. Fixes #570
This commit is contained in:
parent
42bc252460
commit
404401b4de
2 changed files with 30 additions and 4 deletions
|
@ -770,9 +770,6 @@ class Router {
|
|||
} else {
|
||||
$params = end($self->__params);
|
||||
}
|
||||
if (isset($params['prefix']) && strpos($params['action'], $params['prefix']) === 0) {
|
||||
$params['action'] = substr($params['action'], strlen($params['prefix']) + 1);
|
||||
}
|
||||
}
|
||||
$path = array('base' => null);
|
||||
|
||||
|
@ -818,6 +815,9 @@ class Router {
|
|||
} elseif (isset($url[$prefix]) && !$url[$prefix]) {
|
||||
unset($url[$prefix]);
|
||||
}
|
||||
if (isset($url[$prefix]) && strpos($url['action'], $prefix) === 0) {
|
||||
$url['action'] = substr($url['action'], strlen($prefix) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
$url += array('controller' => $params['controller'], 'plugin' => $params['plugin']);
|
||||
|
|
|
@ -1741,7 +1741,7 @@ class RouterTest extends CakeTestCase {
|
|||
|
||||
Router::setRequestInfo(array(
|
||||
array('controller' => 'users', 'action' => 'login', 'company' => true, 'form' => array(), 'url' => array(), 'plugin' => null),
|
||||
array('base' => '/', 'here' => '/', 'webroot' => '/base/', 'passedArgs' => array(), 'argSeparator' => ':', 'namedArgs' => array())
|
||||
array('base' => '/', 'here' => '/', 'webroot' => '/base/')
|
||||
));
|
||||
|
||||
$result = Router::url(array('controller' => 'users', 'action' => 'login', 'company' => false));
|
||||
|
@ -1749,6 +1749,32 @@ class RouterTest extends CakeTestCase {
|
|||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test url generation with prefixes and custom routes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testUrlWritingWithPrefixesAndCustomRoutes() {
|
||||
Router::connect(
|
||||
'/admin/login',
|
||||
array('controller' => 'users', 'action' => 'login', 'prefix' => 'admin', 'admin' => true)
|
||||
);
|
||||
Router::setRequestInfo(array(
|
||||
array('controller' => 'posts', 'action' => 'index', 'admin' => true, 'prefix' => 'admin',
|
||||
'form' => array(), 'url' => array(), 'plugin' => null
|
||||
),
|
||||
array('base' => '/', 'here' => '/', 'webroot' => '/')
|
||||
));
|
||||
$result = Router::url(array('controller' => 'users', 'action' => 'login', 'admin' => true));
|
||||
$this->assertEqual($result, '/admin/login');
|
||||
|
||||
$result = Router::url(array('controller' => 'users', 'action' => 'login'));
|
||||
$this->assertEqual($result, '/admin/login');
|
||||
|
||||
$result = Router::url(array('controller' => 'users', 'action' => 'admin_login'));
|
||||
$this->assertEqual($result, '/admin/login');
|
||||
}
|
||||
|
||||
/**
|
||||
* testPassedArgsOrder method
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue