CakePHP 3.0 URL Parameter

Previously in CakePHP 2.0. I can access the tokenid inside the "if this message" after I clicked the submit button. Apparently now, after I clicked the submit button in CakePHP 3.0, I can no longer receive the tokenid in the "if this is a message condition" field. How can I continue to access the URL parameter in the "if this is a message condition" field? I know this 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() ?>

      

Afterir Feedback,

I added below inside the form.

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

      

+3


source to share


1 answer


If the post you created in the view template file is to a different url, you need to add a token to the form 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 send messages to the same location:



$this->Form->create();

      

With this, you will be able to access the parameter $token

in your controller after POST.

+5


source







All Articles