Redirect |
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!
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.
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;
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 What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(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. |
Welcome Guest, Not a member yet? Register Sign In |