title: CodeIgniter userdata For Session won't work
body: <p>I am trying to create a blog site , i have a database named ci_test it has two table users and article . I have an issue with the session that can't fix. I set-</p>
  <pre><code>$config['encryption_key'] = '1234';
  </code></pre>
  <p>Also, set the property</p>
  <pre><code>$autoload['libraries'] = array('database','session');
  </code></pre>
  <p>But it gives the error :</p>
  <blockquote>
  <p>Severity: Notice</p>
  <p>Message: Undefined property: Admin::$session</p>
  <p>Filename: controllers/admin.php</p>
  <p>Line Number: 18</p>
  </blockquote>
  <p>My login code is:</p>
  <pre><code>&lt;?php
  
  class Login extends MY_Controller{
      
      public function index()
      {
          $this-&gt;load-&gt;helper('form');
          $this-&gt;load-&gt;view('public/admin_login');
      }
  
          public function admin_login()
      {
          $this-&gt;load-&gt;library('form_validation');
  
          $this-&gt;form_validation-&gt;set_rules('username','user name','required|alpha|trim');
          $this-&gt;form_validation-&gt;set_rules('password','password','required');
  
          $this-&gt;form_validation-&gt;set_error_delimiters('&lt;p class=&quot;text-danger&quot;&gt;','&lt;/p&gt;');
  
          if($this-&gt;form_validation-&gt;run())
          {
  
              $username = $this-&gt;input-&gt;post('username');
              $password = $this-&gt;input-&gt;post('password');
  
              $this-&gt;load-&gt;model('loginmodel');
              $login_id = $this-&gt;loginmodel-&gt;login_valid($username, $password);
              if($login_id)
              {
                  //$this-&gt;load-&gt;library('session');
                  $this-&gt;session-&gt;set_userdata('user_id', $login_id);
  
                  redirect('admin/dashboard');
              }
              else{
                  echo 'password dont'; 
              }
  
          }
          else
          {
              $this-&gt;load-&gt;view('public/admin_login');
          }
  
  
      }
  }
  </code></pre>
  <p><strong>Updated from comment login model</strong></p>
  <pre><code>class Loginmodel extends CI_Model{ 
  
  public function login_valid($username, $password) {
  
  $q = $this-&gt;db-&gt;where(['uname'=&gt;$username,'pword'=&gt;$password])-&gt;g‌​et('users'); 
  
  if($q-&gt;num_rows()) { 
  
  return $q-&gt;row()-&gt;id; //return TRUE; } else{ return FALSE; 
  
  } 
  
  }
  </code></pre>
  <p>admin controller:</p>
  <pre><code>&lt;?php
  
  class Admin extends CI_Controller{
      
      public function dashboard()
      {
  
  
          $this-&gt;load-&gt;model('articlesmodel','article');
  
          $articles = $this-&gt;article-&gt;articles_list();
  
          $this-&gt;load-&gt;view('admin/dashboard',['articles'=&gt; $articles]);
      }
  
      public function __construct()
      {
          if(! $this-&gt;session-&gt;userdata('user_id'))
          {
              redirect('login');
          }       
      }
  
  
  }
  </code></pre>
  <p>Model:</p>
  <pre><code>&lt;?php
  
  class Articlesmodel extends CI_Model{
  
      public function articles_list()
      {
          
          $user_id = $this-&gt;session-&gt;userdata('user_id');
          $query = $this-&gt;db-&gt;select('title')-&gt;where('user_data',$user_id)-&gt;get('articles');
                  
              return $query-&gt;result();        
      }
  
  
  }
  </code></pre>
  <p>view:</p>
  <pre><code>&lt;div class=&quot;container&quot;&gt;
      &lt;table class=&quot;table&quot;&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;td&gt;Serial no&lt;/td&gt;
              &lt;td&gt;Article List&lt;/td&gt;
  
              &lt;td&gt;#&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
  &lt;?php if(count($articles)): ?&gt;
      &lt;?php foreach($articles as $article): ?&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  1
              &lt;/td&gt;
              &lt;td&gt;
              &lt;?= $article-&gt;title; ?&gt;
              &lt;/td&gt;
  
              &lt;td&gt;
                  &lt;a class=&quot;btn btn-primary&quot;&gt;Edit&lt;/a&gt;
                  &lt;a class=&quot;btn btn-danger&quot;&gt;Delete&lt;/a&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;?php endforeach;?&gt;
      &lt;?php else:?&gt;
          &lt;tr&gt;
              &lt;td colspan=&quot;3&quot;&gt;Record not found&lt;/td&gt;
          &lt;/tr&gt;
  &lt;?php endif;?&gt;  
      &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>