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

Response redirect not working on 2.0.5

Don't know why but on 2.0.5 my redirects are not working at all. (It works well until now)

  // on a controller
    public function logoutAction()
    {
        $this->auth->logout();
        $this->session->destroy();
        $this->flash->success("User disconnects.");
        $this->response->redirect('/');
        die("Why is this happening");
    }

it reachs the die :(

FYI Redirect does not change the execution flow, you need:

public function logoutAction()
    {
        $this->auth->logout();
        $this->session->destroy();
        $this->flash->success("User disconnects.");
        return $this->response->redirect('/');
        die("Why is this happening");
    }


5.7k

To add to what @andresgutierrez said, you should also always send your response when doing a redirect:

$this->response->redirect('/')->send();

I thought the redirect already redirectsas the name says. Actually, the this->response->redirect('/');was working on my logout until 2.0.3 I will change it as you said. Thanks.



7.5k

The return in the example authored by @andresguiterrez would not execute the die would it?



5.7k

The return in the example authored by @andresguiterrez would not execute the die would it?

It shouldn't because you are returning the result of the function on the previous line.