Welcome Guest, Not a member yet? Register   Sign In
Auto-executing a function on all pages
#1

[eluser]hybrid11[/eluser]
Hi everyone,

I need to check if a user has already been added to one my database tables every time they hit any page on my application.

I don't want to have to call the function in every one of my controllers since it needs to be called on all the pages.
Hence, I searched around and it looks like my options are to either create a library or a base controller. Would that be right way to solve this?

Thanks!
#2

[eluser]Madmartigan1[/eluser]
You got it. Do both!

Make a library to run your check, create MY_Controller, load and run the library in the constructor.

GL Smile
#3

[eluser]hybrid11[/eluser]
cool, thanks for the help!
#4

[eluser]hybrid11[/eluser]
So I implemented that solution and it works great.

Quick question though, by following this solution, is my custom library instantiated on a per session basis (ie: every time a new user hits my site)?
#5

[eluser]Madmartigan1[/eluser]
If it's in MY_Controller, it will be run every time a controller is loaded. Basically once per page load.




Theme © iAndrew 2016 - Forum software by © MyBB