title: How to make a dynamic variable value global in CodeIgniter?
body: <p>How to make a global variable that always changing?</p>
  
  <p>I want to create something like <code>protected $global_data;</code> in <code>controller</code> <code>Global_data.php</code> that can be called by a lot of controller, and return variable <code>$global_data</code> value to whenever <code>controller</code> that has <code>$this-&gt;load-&gt;library('../controllers/Global_data')</code>.</p>
  
  <p>But when I tried to call it, it gives me this error <code>Unable to locate the specified class: Session.php</code>, so I think <code>CodeIgniter 3.1.8</code> not allowed me to do this.</p>
  
  <p>So how to achieve what I'm looking for? do I need to put it on <code>model</code> instead, <code>library</code> file or is there another way to do it?</p>
  
  <p>Thank you.</p>
  
  <p>Here is <code>Global_data.php</code> content</p>
  
  <pre><code>protected $global_data;
  
  public function __construct()
  {
      parent::__construct();
  
      $this-&gt;global_data = array(
          'can_be_anything'    =&gt; 'can_be_anything',
          'can_be_anything'    =&gt; 'can_be_anything',
          'can_be_anything'    =&gt; 'can_be_anything',
          'can_be_anything'    =&gt; 'can_be_anything',
      );
  }
  </code></pre>
  
  <p><code>Can_be_anything_controller.php</code> content</p>
  
  <pre><code>class Can_be_anything_controller extends CI_Controller {
      public function __construct()
      {
          parent::__construct();
  
          $this-&gt;load-&gt;library('../controllers/Global_data');
      }
  
      public function index()
      {
          $data = $this-&gt;global_data;
          $data['page_title']     = 'Dashboard';
          $data['page_directory'] = 'pages/dashboard';
          $this-&gt;load-&gt;view('template', $data);
      }
  }
  </code></pre>