1

是否可以通过重定向传递参数?我尝试了很多选择,但似乎没有任何效果。我的最新方法是:

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

然后我创建了一条路线:

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

但我得到的只是users/helloworld/myId

4

2 回答 2

2

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

于 2012-01-24T00:53:57.787 回答
1

您可以执行以下操作,而不是定义单独的路由来传递参数。假设您想将 2 个参数:$arg1$arg2传递给用户控制器的helloworld操作:

return $this->redirect(array(
'Users::helloworld',
'args' => array(
        $arg1,
        $arg2
    )
));
于 2012-05-27T20:21:19.610 回答