CakePHP 3.0 URL 参数

CakePHP 3.0 URL Parameter

以前,在 CakePHP 2.0 中。点击提交按钮后,我可以访问 'if it a post condition' 中的 tokenid。显然现在,在我点击 CakePHP 3.0 中的提交按钮后,我不再能够在 'if it a post condition' 中接收 tokenid。如何继续访问 'if it a post condition' 中的 URL 参数?我知道,这真的很简单。谁能启发我?我错过了什么?

URL

/users/reset/15d3a535ecdd4ec705378b146ef572cf5bb9bfc2

控制器

public function reset($token=null) {

    if ($token) { //I am able to get the tokenid here. 

    Debugger::Dump($this->request->pass[0]); //I am able to get the tokenid here. 
    Debugger::Dump($this->request->params['pass'][0]); //I am able to get the tokenid here. 

         if ($this->request->is(['post'])) {
                 Debugger::Dump($token) //I am no longer able to get the tokenid.
                 Debugger::Dump($this->request->pass[0]); //I am no longer able to get the tokenid.
                 Debugger::Dump($this->request->params['pass'][0]); //I am no longer able to get the tokenid.
         }
    }
}

查看

<?php echo $this->Form->create(null, ['url' => ['controller' => 'Users', 'action' => 'reset']]); ?>
<?php echo $this->Form->input('password'); ?>
<?php echo $this->Form->button('Submit', ['type' => 'submit']); ?>
<?php echo $this->Form->end() ?>

经过Ofir的反馈,

我在表格中添加了以下内容。

<?php echo $this->Form->input('resetToken', array('type'=> 'hidden','value'=>$this->request->pass[0])); ?>

如果您在视图模板文件中创建的 for posting 到另一个 URL,您需要将令牌添加到表单操作 url:

$this->Form->create(null, ['url' => ['controller' => 'Users', 'action' => 'reset', $token]]);

如果您 post 前往相同的 URL,则无需指定 URL,因为它将 post 前往相同的位置:

$this->Form->create();

这样,您将能够在 POST 后访问控制器中的 $token 参数。