douxing9641 2015-06-28 06:43
浏览 50
已采纳

CakePHP 3.0 URL参数

Previously, in CakePHP 2.0. I am able to access the tokenid inside the 'if it a post condition' after I hit the submit button. Apparently now, after I hit the submit button in CakePHP 3.0, I am no longer able to receive the tokenid in the 'if it a post condition'. How can I continue to access the URL parameter inside the 'if it a post condition'? I know, it is really something simple. Can anyone enlighten me? What am I missing?

URL

/users/reset/15d3a535ecdd4ec705378b146ef572cf5bb9bfc2

Controller

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.
         }
    }
}

View

<?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() ?>

After Ofir feedback,

I added the below inside the form.

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

1条回答 默认 最新

  • dpo15099 2015-06-28 07:43
    关注

    If the for you created in the view template file is posting to another URL, you need to add the token to the form action url:

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

    If you are posting to the same URL, there is no need to specify the URL, as it will post to the same location:

    $this->Form->create();
    

    With that, you will be able to access the $token param in your controller after a POST.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 把VMware项目复制到另一台电脑
  • ¥15 onlyoffice编辑完后立即下载,下载的不是最新编辑的文档
  • ¥15 求caverdock使用教程
  • ¥15 Coze智能助手搭建过程中的问题请教
  • ¥15 12864只亮屏 不显示汉字
  • ¥20 三极管1000倍放大电路
  • ¥15 vscode报错如何解决
  • ¥15 前端vue CryptoJS Aes CBC加密后端java解密
  • ¥15 python随机森林对两个excel表格读取,shap报错
  • ¥15 基于STM32心率血氧监测(OLED显示)相关代码运行成功后烧录成功OLED显示屏不显示的原因是什么