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 on BaseController

Hi, i've tried to perform a redirect inside the BaseController but it doesn't work. I think this is the default behaviour but i want to know if there is a method to perform the redirect. Actually i'm using this:

header("Location: *url*");
die();

Thank you :)

edited Jul '15

What do you have in basecontroller? an action?

edited Jul '15

for redirect inside controller better use

return $this->response->redirect("url")->send();

https://docs.phalcon.io/en/latest/reference/response.html#making-redirections

Not an action, simply a function that check something and if it fail i need a redirect.

I've tried to use ->send() method, but doesn't work.

What do you have in basecontroller? an action?



12.2k
Accepted
answer
edited Aug '15

There are two approaches for this.

This is an explanation between differences https://stackoverflow.com/questions/21301624/phalcon-redirection-and-forwarding

Also forward is void method, so you do not have use return.

Thank you :)