Redirect - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Redirect (/showthread.php?tid=72338) |
Redirect - oliver - 12-06-2018 Hi, I have created a BaseController extending CI Controller : Code: <?php namespace App\Controllers; Code: <?php namespace App\Controllers; Can someone confirm this is the expected result? Why is redirection not working in BaseController? Thanks in advance! RE: Redirect - kilishan - 12-06-2018 The redirect method returns a RedirectResponse class in CI4, which you must return from your methods. In Home2 it's doing parent::init(), but not returning the RedirectResponse if it is returned. A second issue you'll run into, though, is that redirects cannot be returned from class constructors now, since we are using a class. You should instead look into using Controller Filters for those type of situations. RE: Redirect - oliver - 12-09-2018 Hi, Thanks for your answer, Kilishan. I've read the guide concerning filters : seems to be a real improvement in CI4! But I still can't get my redirect working. I created application/Filters/AuthFilter.php : Code: <?php namespace App\Filters; Then I changed Config/Filters: Code: <?php namespace Config; But when I try to reach Home2::index, only "filtered" is displayed, no redirection takes place : Code: <?php namespace App\Controllers; Code: <?php namespace App\Controllers; RE: Redirect - InsiteFX - 12-09-2018 I have learned a lot by looking at Lonnie's sample code like his Myth Auth etc; You can find them here. Lonnie Ezell - GitHub RE: Redirect - Inc33 - 04-25-2020 (12-06-2018, 12:56 PM)kilishan Wrote: The redirect method returns a RedirectResponse class in CI4, which you must return from your methods. In Home2 it's doing parent::init(), but not returning the RedirectResponse if it is returned.This needs to be made clear in the documentation, as I spent a bit of time as well to figure it out... In the documentation it only mentions that it redirects a response, but doesn't state clearly how you need to handle that response. |