CodeIgniter Forums
Redirecting in BaseController? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: Redirecting in BaseController? (/showthread.php?tid=74831)



Redirecting in BaseController? - next2heaven - 11-12-2019

So in previous Codeigniter versions I usually had a base controller that all other controllers extended from.  In that controller I would check if the user was logged in and if not, redirect them to a login page.  I'm not able to do redirecting in the base controller in CI4.  

How should I handle checking if the user is logged in and if not sending them to the login page without having to write an if statement on all of my page controllers?


RE: Redirecting in BaseController? - MGatner - 11-12-2019

There have been a number of posts on this topic already. Search the forums for some great examples, but the short answer is you want to look into Filters (https://codeigniter4.github.io/CodeIgniter4/incoming/filters.html). This might also be helpful: https://github.com/lonnieezell/myth-auth#restricting-by-route


RE: Redirecting in BaseController? - next2heaven - 11-13-2019

Thank you. Must have used the wrong search terms. I did search before posting. I appreciate the links.