通过重定向传递参数
是否可以通过重定向传递参数?我尝试了很多选择,但似乎没有任何效果。我最新的方法是:
return $this->redirect(array('Users::helloworld', 'args' => array('id' => 'myId')));
然后我创建了一条路线:
Router::connect('/Users/helloworld?id={:id}', array('controller' => 'Users', 'action' => 'helloworld'));
但我得到的只是 users/helloworld/myId
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
args
是路由的一部分,将使用非常通用的路由(不是您创建且不需要的路由)转换为 URL要获取查询字符串,只需使用
?
键:测试:https://github.com/UnionOfRAD/lithium/blob/master/tests/cases/net/http/RouteTest.php#L374-405
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:The test for that: https://github.com/UnionOfRAD/lithium/blob/master/tests/cases/net/http/RouteTest.php#L374-405
您可以执行以下操作,而不是定义单独的路由来传递参数。
假设您想传递 2 个参数: $arg1 & $arg2 到您的 Users 控制器的 helloworld 操作:
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: