title: Codeigniter Global data to be used on controllers
body: <p>So a brief intro, I'm trying to make a web app for posting stories and viewing stories.</p>
  
  <p>I divided my controller into two, story controller and user controller. Any function i write that involves the story part of my project i write it inside story controller and any user function i have is in user controller.</p>
  
  <p>For example:</p>
  
  <blockquote>
    <p>public function add_story(){} is in story controller.</p>
    
    <p>public function register(){} is in user controller.</p>
  </blockquote>
  
  <p>Also in loading my views i separated them into templates and pages.</p>
  
  <p>Inside templates are the header/navbar/footer. The pages are all  contents of my html so only the pages differ.</p>
  
  <pre><code>$this-&gt;load-&gt;view('template/header');
  $this-&gt;load-&gt;view('template/navbar');
  $this-&gt;load-&gt;view('pages/page_name');
  $this-&gt;load-&gt;view('template/footer');
  </code></pre>
  
  <p>Now my question is in the navbar. I want to add a notification function. I already have it in my head i just need to implement it but i'm indecisive as to how i will implement it. Obviously i need the function to be <strong>GLOBAL</strong> else i'll have to declare it to all functions to my controllers. That will only make my code longer and hard to follow.</p>
  
  <p>I'll simply make a database table named as notification. With an essential column as status with only 2 possible variable as 'seen' 'unseen'. Since i have a user that has two roles(author and reader) for author any new review submitted to the story posted and for reader any new chapter added to bookshelved/bookmarked story. </p>
  
  <p>Anyhow, i want to make a global function to parse the table for all updates to the user logged in(recent 5) and print them inside a dropdown on my navbar and just set in html a php if statement whether it is unseen or not and if it is highlight it.(rough idea, adjusted later during implementation)</p>
  
  <p>My problem is that the first way i thought of to implement this was to make use of a constructor or index function to my controllers and store the data in a global <code>$data = array('notification' =&gt; array());</code> variable. </p>
  
  <p>Then i searched google and found another way and that was to use base_controller. I also havent implemented checks in my controller if a user is logged in or not. I can do this in a constructor along with the notification but i also can do this with the base controller right?</p>
  
  <p>anyway i would like to ask if which of the two is better(im leaning more on the 2nd but i could be wrong) and/or if there is a better method?</p>