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.

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

报告相同问题?

悬赏问题

  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题