I have a variable, contaning data that should be present in the entire site. Instead of passing this data to each view of each controller, I was wondering if there is a way
Create a MY_Controller.php
file and save it inside the application/core folder. In it, something like:
class MY_Controller extends CI_Controller {
public $site_data;
function __construct() {
parent::__construct();
$this->site_data = array('key' => 'value');
}
}
Throughout your controllers, views, $this->site_data
is now available.
Note that for this to work, all your other controllers need to extend MY_Controller
instead of CI_Controller
.
you can use $this->load->vars('varname', $data);[ or load data at 1st view only] onse and use in any loaded views after this