[英]Passing parameters via redirect
是否可以通过重定向传递参数? 我尝试了很多选择,但似乎没有任何效果。 我最新的方法是:
return $this->redirect(array('Users::helloworld', 'args' => array('id' => 'myId')));
然后我创建了一条路线:
Router::connect('/Users/helloworld?id={:id}', array('controller' => 'Users', 'action' => 'helloworld'));
但我得到的只是users/helloworld/myId
args
是路由的一部分,将使用非常通用的路由(而不是您创建的不需要的路由)转换为URL。
要获取查询字符串 ,只需使用?
键:
return $this->redirect(array(
'Users::helloworld',
'?' => array('id' => $myId)
));
// will use the route:
// /{:controller}/{:action}/{:args}
// and generate
// /users/helloworld?id=$myId
该测试: https : //github.com/UnionOfRAD/lithium/blob/master/tests/cases/net/http/RouteTest.php#L374-405
除了定义传递参数的单独路径外,您还可以执行以下操作。 假设您要将两个参数: $ arg1 & $ arg2传递给Users控制器的helloworld操作:
return $this->redirect(array(
'Users::helloworld',
'args' => array(
$arg1,
$arg2
)
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.