mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding support for Router::reverse() to operate on CakeRequest objects.
This commit is contained in:
parent
7e25d94258
commit
e11f7da896
2 changed files with 15 additions and 1 deletions
|
@ -1012,10 +1012,13 @@ class Router {
|
|||
* Since parsed URL's contain additional 'pass' and 'named' as well as 'url.url' keys.
|
||||
* Those keys need to be specially handled in order to reverse a params array into a string url.
|
||||
*
|
||||
* @param array $param The params array that needs to be reversed.
|
||||
* @param mixed $param The params array or CakeRequest object that needs to be reversed.
|
||||
* @return string The string that is the reversed result of the array
|
||||
*/
|
||||
public static function reverse($params) {
|
||||
if ($params instanceof CakeRequest) {
|
||||
$params = $params->params;
|
||||
}
|
||||
$pass = $params['pass'];
|
||||
$named = $params['named'];
|
||||
$url = $params['url'];
|
||||
|
|
|
@ -2156,6 +2156,17 @@ class RouterTest extends CakeTestCase {
|
|||
);
|
||||
$result = Router::reverse($params);
|
||||
$this->assertEqual($result, '/eng/posts/view/1?foo=bar&baz=quu');
|
||||
|
||||
$request = new CakeRequest('/eng/posts/view/1');
|
||||
$request->addParams(array(
|
||||
'lang' => 'eng',
|
||||
'controller' => 'posts',
|
||||
'action' => 'view',
|
||||
'pass' => array(1),
|
||||
'named' => array(),
|
||||
'url' => array('url' => 'eng/posts/view/1')
|
||||
));
|
||||
$result = Router::reverse($request);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue