title: Retrieve session data Codeigniter
body: <p>I'm working on a messaging system and want the user's userid to be posted to the database along with the message. Right now, the message is posting to the database, but with a user ID of 0. </p>
  
  <p>How can I get the user ID from the session data to post to the database along with the message? Sidenote: I'm using Tank Auth for authentication. (From the mysql side, user_id in the message table is a foreign key referencing id in the users table). </p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>function index() {
  
      if ($this-&gt;input-&gt;post('submit')) {
              $id = $this-&gt;input-&gt;post('user_id');
              $message = $this-&gt;input-&gt;post('message');
  
              $this-&gt;load-&gt;model('message_model');
              $this-&gt;message_model-&gt;addPost($id, $message);
          }
      }   
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code>function addMessage($id, $message) {
          $data = array(
              'user_id' =&gt; $id,
              'message' =&gt; $message
          );
  
          $this-&gt;db-&gt;insert('message', $data);
      }
  </code></pre>