We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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.

page redirection in controllers with params

public function myAction()
{
    if ($this->request->isPost()) {
        //....
        .
        .
        .
        //page redirection when success, how to make it works
        return $this->response->redirect([
            'controller' => 'Index',
            'action' => 'message',
            'message' => 'Data saved successfully.'
        ]);
    }
    $this->view->pick('....');
    .
    .
    .
}


51.0k
Accepted
answer

You should redirect based on a named route. For example, if you have a route named "message"

         $this->view->disable();
         return $this->response->redirect(array(
            "for" => "message",
            "message" => "Data saved successfully.",
            "controller" => "index"
         ));


29.0k
edited Jun '15

OK, thanks.

$router->add(...)->setName('message');

You should redirect based on a named route. For example, if you have a route named "message"

       $this->view->disable();
       return $this->response->redirect(array(
          "for" => "message",
          "message" => "Data saved successfully.",
          "controller" => "index"
       ));