CodeIgniter Forums
Data flow (Controller filters and redirects) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Data flow (Controller filters and redirects) (/thread-77272.html)



Data flow (Controller filters and redirects) - legon614 - 08-10-2020

I have an application where I need to fetch alot of data from MySQL and I do so with my models. I use my models in the BaseControllers construct to be able to use them in all my controllers.

I also have a check in my BaseController and if the data I fetch is not what I except I redirect the user to the login page. However, redirects doesn't seem to work from the constructor (I 
use return redirect()->to(base_url('/account/logged_out'))Wink. So I figured it's time to get to learn controller filters which seems to be great. However - I need my database data in the filter. OR be able to fetch the data in the filter and make the data globally accessible. Is that possible?

I don't see a way of adding arguments to filters if I don't use it from a route adder.

I'm trying to figure out a way of getting the database data that is fetched in the BaseControllers construct everywhere. If I could add data to the request object or a memcache or something? How would you approach this?

Thanks
Tony