Welcome Guest, Not a member yet? Register   Sign In
auto execute code
#1

[eluser]smick[/eluser]
Hello,

How would I auto execute a function every time any controller loads in CI?

I don't want to have to drop a line into every controller because the function may change over time. Essentially, I need to keep track of whether a set of session data exists, and if not I set them. It's geolocation data for user location and search location.

How would I go about auto running a function?

Thanks for any help!
#2

[eluser]adaxa[/eluser]
You can create MY_Controller class and put that function in it construct.
After that you can extend every controller class with MY_Controller.
#3

[eluser]smick[/eluser]
Actually, thanks for your quick reply, I found a solution, which aws simply to auto load a model and call a function of the model in it's constructor. like this:

class User extends Model {
function User(){
parent::Model();
$this->locate();
}
function locate() { }
}




Theme © iAndrew 2016 - Forum software by © MyBB