Data available for all views in codeigniter

codeigniter

Solution

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`.

Problem

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 to make this data available for every view in the site. Pd. Storing this data as a session variable / ci session cookie is not an option. Thanks so much.

Original source