以前,在CakePHP 2.0中。在我点击提交按钮后,我能够访问'if if a post condition'中的tokenid。显然现在,在我点击CakePHP 3.0中的提交按钮后,我不再能够在'if it a post condition'中收到tokenid。如何继续访问“if if a post condition”中的URL参数?我知道,这真的很简单。任何人都可以开导我吗?我错过了什么?
网址
/用户/复位/ 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])); ?>
答案 0 :(得分:5)
如果您在视图模板文件中创建的for将发布到另一个URL,则需要将该标记添加到表单操作URL:
$this->Form->create(null, ['url' => ['controller' => 'Users', 'action' => 'reset', $token]]);
如果您要发布到同一个网址,则无需指定网址,因为它会发布到同一位置:
$this->Form->create();
通过这种方式,您可以在POST后访问控制器中的$token
参数。