1

Is it possible to pass parameters via redirect? I tried a lot of options, but nothing seems to work. My latest approach is:

return $this->redirect(array('Users::helloworld', 'args' => array('id' => 'myId')));

then I created a route:

Router::connect('/Users/helloworld?id={:id}', array('controller' => 'Users', 'action' => 'helloworld'));

but all I get is users/helloworld/myId

Charles
  • 50,943
  • 13
  • 104
  • 142
Mewel
  • 1,279
  • 15
  • 21

2 Answers2

2

args is part of the routes and will be converted into an URL using the very generic route (not the one you created and don't require)

To get a query string, simply use the ? key:

return $this->redirect(array(
    'Users::helloworld',
    '?' => array('id' => $myId)
));
// will use the route:
//    /{:controller}/{:action}/{:args}
// and generate
//    /users/helloworld?id=$myId

The test for that: https://github.com/UnionOfRAD/lithium/blob/master/tests/cases/net/http/RouteTest.php#L374-405

greut
  • 4,305
  • 1
  • 30
  • 49
1

Instead of defining a separate route to pass arguments, you could just do the following. Lets say you want to pass 2 arguments: $arg1 & $arg2 to the helloworld action of your Users controller:

return $this->redirect(array(
'Users::helloworld',
'args' => array(
        $arg1,
        $arg2
    )
));
abhshkdz
  • 6,335
  • 1
  • 21
  • 31