문제

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

도움이 되었습니까?

해결책

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

다른 팁

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
    )
));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top