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

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

其他提示

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

return $this->redirect(array(
'Users::helloworld',
'args' => array(
        $arg1,
        $arg2
    )
));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top