I am developing a CRM for our agency in Codeigniter and I have a question that I can’t seem to find a solid answer on. If I have a task that I do on the majority of methods in a controller, is there any way to define that action only once? For instance…
Every view call gets passed the $data variable, like so…
$this->load->view('templates/template.php', $data);
So if I am doing something like getting the admins information in every function of the controller, how can i tell it to do that action ONE time and pass it to all my functions.
Like this…
$data['admin'] = $this->Crm_model->get_admin();
I’ve tried putting that ^ in the constructor and it doesn’t work. Any ideas?
If you do:
in the constructor,
$data‘s scope is limited to the constructor. You need to create it as a class property so it is scoped to the entire class. Do this insteadin the constructor, and then in other methods, you can access the array by doing
$this->dataHere’s an example: