We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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');


8.4k
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.