title: Codeigniter: using a custom MY_Controller effectively for user authentication - passing vars to models etc
body: <p>I am utilizing a custom MY_Controller to authenticate users on my Codeigniter website.</p>
  
  <p>I utilize <code>$this-&gt;load-&gt;vars($data);</code> such that I can access the users information in views.</p>
  
  <p>My first question is, does <code>$this-&gt;load-&gt;vars($data);</code> allow access in models, and if so how - i couldn't find any information. If not, how can I get my logged in users username to my models without having to pass it through a controller every time?</p>
  
  <p>Secondly... if the user is not logged in, I redirect them <code>redirect(base_url() . 'account/login');</code></p>
  
  <p>This works great, except because my account controller also extends MY_Controller, it gets stuck in an infinite redirect loop. I can just not extend the custom controller for this page, but I see no reason why a logged in user should not still be able to look at the login page.. any ideas?</p>
  
  <p>Finally.. if a user is logged in, <code>$user['username']</code> is defined in my views.
  If a user is not logged in, it is not defined.</p>
  
  <p>As such if i have <code>if($user['username']!=''){</code> within my code, when a user IS logged in, all is fine and the code executes, however when no user is logged in errors pop up as regards an undefined variable being used in an if statement...</p>
  
  <p>Codeigniter being difficult..</p>
  
  <p>What is the work around here?</p>
  
  <p>Many Thanks !!</p>