CakePHP 3.0 URL参数
之前,在CakePHP2.0中。在我点击提交按钮后,我能够访问“if it a post condition”中的tokenid。显然现在,在我点击CakePHP 3.0中的submit按钮之后,我不再能够在“if it a post condition”中接收tokenid。如何继续访问“if it a post condition”中的URL参数?我知道,这真的很简单。谁能启发我?我错过了什么 URL /用户/重置/15d3a535ecdd4ec705378b146ef572cf5bb9bfc2 控制器CakePHP 3.0 URL参数,php,cakephp,cakephp-2.0,cakephp-3.0,Php,Cakephp,Cakephp 2.0,Cakephp 3.0,之前,在CakePHP2.0中。在我点击提交按钮后,我能够访问“if it a post condition”中的tokenid。显然现在,在我点击CakePHP 3.0中的submit按钮之后,我不再能够在“if it a post condition”中接收tokenid。如何继续访问“if it a post condition”中的URL参数?我知道,这真的很简单。谁能启发我?我错过了什么 URL /用户/重置/15d3a535ecdd4ec705378b146ef572cf5bb9bf
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])); ?>
如果在视图模板文件中为您创建的标记正在发布到另一个URL,则需要将标记添加到表单操作URL:
$this->Form->create(null, ['url' => ['controller' => 'Users', 'action' => 'reset', $token]]);
如果要发布到同一URL,则无需指定URL,因为它将发布到同一位置:
$this->Form->create();
这样,您就可以在POST后访问控制器中的
$token
参数。如果我错了,请纠正我,但令牌id是通过GET
传递的,据我所知,您不能通过GET
和POST
在同一请求上传递数据。考虑用令牌ID的值向窗体中添加隐藏字段。Ofir,我以前也尝试过您的方法。但只要我按下提交按钮。它不接收$this->request->data['resetToken'],因为它依赖于$this->request->pass[0](URL参数)。实际上,我可以在CakePHP2.0中实现上面提到的功能,但在CakePHP3.0中无法实现。真奇怪。。。