In my CI controllers I have these three functions:
function _temp ($view,$data="") {
$this->load->view('temp/nm-header',$data);
$this->load->view($view,$data);
$this->load->view('temp/footer',$data);
}
function _qs($val) {
return $this->session->userdata($val);
}
function _qp($val) {
return $this->input->post($val);
}
I would like to have a central controller for this, rather than to have to copy/paste these methods in every controller I have. Will making a library do the trick? If so…
$ci =& get_instance
How do I make this variable above be available in all of the menthods I have in my library class?
Thanks.
No need to create a library. Instead, create a base controller called
MY_Controllerfor your common methods, and have your other controllers extend from it, like this:MY_Controller:
Any other controller you want to have access to your common methods: