Redirect Not Working CI4 |
err, if anyone needs a quick fix for a redirect I just use this:
header('Location: /login'); exit(); it works everywhere so far, I actually have a check login function in my base controller where this is working from. Beware though, it seems an exit() will prevent any of your "after stuff happens" events or filters from working. Update: also a check login in base controller doesn't seem like a good idea anymore, so I made it as a public static function in a library
You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
(11-07-2019, 07:57 AM)Programaciones Web Wrote: Hello Guys. I started a new Project with CI4 to see the new features and I am struggling trying to redirect between pages. Remove de "base_url", like this: PHP Code: return redirect()->to('/login'); That way works for me. (04-20-2020, 02:42 AM)Leo Wrote: err, if anyone needs a quick fix for a redirect I just use this: Thanks for the suggestion. The redirect worked fine using the header('Location...) way. However I still lost session data in the redirected location which was my problem. Have you tried it with session data?
@jim1001
Yes, the sessions work fine. Just put session() in the controller or wherever you are calling the redirect, and put session() whereever you are redirecting to. Also, in my case, I had aggressive session cleaning after each controller, written in an Event - but the exit(), called after header("Location: .... prevented all that, and my session worked in next controller/method/location
You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
its prettly simple actually
for more clear precise answer u have to add 3 parameters inside the declared constructor PHP Code: public function initController($request, $response, $logger) |
Welcome Guest, Not a member yet? Register Sign In |