cakephpresponse.redirectcakephp-3.2

redirect to another action with hidden or post parameter in cakephp 3


I'm working cakephp 3.2

I have to redirect from one action to another along with some data with it. The data to be transmitted is large and in a variable and also sensitive.

Passing the data in parameter can be achieved by

return $this->redirect(['controller' => 'MyController', 'action' => 'myAction', $param]);

But this gives url as

/my-controller/my-action/param

I do not want to show param in the url.

Is there some way to do this ?


Solution

  • Is there some way to do this ?

    You could simply use the session to stash the data.

    E.g. In the function with post data:

    $this->request->session()->write(
        'my-stuff', 
        $this->request->data
    );
    $this->redirect('/somewhere/else');
    

    In the function that needs that data, read it out of the session:

    $myStuff = $this->request->session()->read('my-stuff');
    if (!$myStuff) {
        return $this->redirect('/start/point');
    }
    ...