title: Codeigniter variables from constructor are undefined
body: <p>I'm using CI's Auth Tank library to query records for certain users. </p>
  
  <p>The variable <code>$user_id = tank_auth-&gt;get_user_id();</code> grabs the user id from the session. I want to pull records where <code>user_id = $user_id</code>.</p>
  
  <p>From what I understood, constructors can load variables each time a class is initiated. Sort of like global variables. So I figured I'll set my <code>$user_id</code> in a model constructor so I can use it for multiple functions within the model class. </p>
  
  <pre><code>class My_model extends Model {
  
      function My_model() 
      {
          parent::Model();
          $user_id = $this-&gt;tank_auth-&gt;get_user_id();     
      }
  
          function posts_read() //gets db records for the logged in user
      {       
          $this-&gt;db-&gt;where('user_id', $user_id);
          $query = $this-&gt;db-&gt;get('posts');
          return $query-&gt;result();
      }
  }
  </code></pre>
  
  <p>Next, I'm loading the model, creating an array in my controller, and sending the data to my view where I have a foreach loop.</p>
  
  <p>When testing I get</p>
  
  <blockquote>
    <p>Message: Undefined variable: user_id</p>
  </blockquote>
  
  <p>in my model. It works however if I define the <code>$user_id</code> variable in my <code>posts_read</code> function, but I don't want to define it in every function that needs it. </p>
  
  <p>What am I doing wrong here?</p>