Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Redirect with params

Is there a way to redirect to a page passing params? I have try this below, but not working:

$this->response->redirect('posts/index', $user );



182
Accepted
answer
edited May '19
$this->dispatcher->forward(
  [
    'controller' => 'posts',
    'action' => 'index',
    'user' => $user
  ]
);

action:

$this->dispatcher->getParam('user');


2.2k
edited May '19

you cannot pass parameters by HTTP redirect unless the using URL parameters (aka. query string).

$this->response->redirect('posts/index/' . 'someParameter');

Your best bet would be to set a session variable before the redirect, and read it after.

Ok, I got it. But this->dispeacher->forward() flows the content to another action, and when I turn back in the browser, the page is down. Thanks for the answers.