Adding support for Router::reverse() to operate on CakeRequest objects.

This commit is contained in:
Mark Story 2010-05-02 02:19:32 -04:00
parent 7e25d94258
commit e11f7da896
2 changed files with 15 additions and 1 deletions

View file

@ -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'];

View file

@ -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);
}
/**