cakePHP3:如何通过redirect()向操作发送参数?

fra*_*lbo 3 cakephp cakephp-3.0

在一个动作中,我想通过重定向将发送参数发送到另一个动作。

因此,当我在文档(http://book.cakephp.org/3.0/en/controllers.html#redirecting-to-other-pages)中阅读此文件时:

return $this->redirect(['action' => 'edit', $id]);
Run Code Online (Sandbox Code Playgroud)

我写:

public function activate($user_id, $token) {

    //.... of course $user->username is not null here
    return $this->redirect(['action' => 'login', $user->username]);

    //....
}
Run Code Online (Sandbox Code Playgroud)

在我的目标动作中:

public function login($username = null) {

    //...

    debug($username);  // just displays null

    //...
}
Run Code Online (Sandbox Code Playgroud)

我不知道问题是在redirect()还是在login()中。无论如何,debug($ this-> request)不会显示任何传递的参数。

问候,

小智 5

仅当登录功能在同一控制器中并且不需要返回时,以上代码才有效。否则,我们还需要为重定向定义控制器。喜欢 :

$this->redirect(['controller'=>'YourController','action' => 'login', $user->username]);
Run Code Online (Sandbox Code Playgroud)