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

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.2k
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.1k
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"
       ));