title: Undefined property: CI::$session
body: <p>I am having trouble loading my model on my login page. It has a problem with sessions on here. I have a security class helper which $key is part of it. But I think it is to do with session as error says.</p>
  
  <p>I think I have set up num rows correct not sure if also that may be cause of it.</p>
  
  <pre><code>A PHP Error was encountered
  Severity: Notice
  Message: Undefined property: CI::$session
  Filename: core/Model.php
  Line Number: 51
  </code></pre>
  
  <p><strong>model</strong></p>
  
  <pre><code>&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  class Users_model extends CI_Model {
  
      private $user_id;
      private $username;
      private $permission = array();
  
      public function __construct() {
  
          if (isset($this-&gt;session-&gt;userdata['user_id'])) {
              $user_query = $this-&gt;db-&gt;query("SELECT * FROM " . $this-&gt;input-&gt;post('dbprefix') . "user WHERE user_id = '" . (int)$this-&gt;session-&gt;userdata['user_id'] . "' AND status = '1'");
  
              if ($user_query-&gt;num_rows) {
                  $this-&gt;user_id = $user_query-&gt;row['user_id'];
                  $this-&gt;username = $user_query-&gt;row['username'];
  
                  $this-&gt;db-&gt;query("UPDATE " . $this-&gt;input-&gt;post('dbprefix') . "user SET ip = '" . $this-&gt;db-&gt;escape($this-&gt;input-&gt;server['REMOTE_ADDR']) . "' WHERE user_id = '" . (int)$this-&gt;session-&gt;userdata['user_id'] . "'");
  
                  $user_group_query = $this-&gt;db-&gt;query("SELECT permission FROM " . $this-&gt;input-&gt;post('dbprefix'). "user_group WHERE user_group_id = '" . (int)$user_query-&gt;row['user_group_id'] . "'");
  
                  $permissions = unserialize($user_group_query-&gt;row['permission']);
  
                  if (is_array($permissions)) {
                      foreach ($permissions as $key =&gt; $value) {
                          $this-&gt;permission[$key] = $value;
                      }
                  }
              } else {
                  $this-&gt;logout();
              }
          }
      }
  
      public function login($username, $password) {
          $user_query = $this-&gt;db-&gt;query("SELECT * FROM " . $this-&gt;input-&gt;post('dbprefix') . "user WHERE username = '" . $this-&gt;db-&gt;escape($username) . "' AND (password = SHA1(CONCAT(salt, SHA1(CONCAT(salt, SHA1('" . $this-&gt;db-&gt;escape($password) . "'))))) OR password = '" . $this-&gt;db-&gt;escape(md5($password)) . "') AND status = '1'");
  
          if ($user_query-&gt;num_rows) {
              $this-&gt;session-&gt;userdata['user_id'] = $user_query-&gt;row['user_id'];
  
              $this-&gt;user_id = $user_query-&gt;row['user_id'];
              $this-&gt;username = $user_query-&gt;row['username'];         
  
              $user_group_query = $this-&gt;db-&gt;query("SELECT permission FROM " . $this-&gt;input-&gt;post('dbprefix') . "user_group WHERE user_group_id = '" . (int)$user_query-&gt;row['user_group_id'] . "'");
  
              $permissions = unserialize($user_group_query-&gt;row['permission']);
  
              if (is_array($permissions)) {
                  foreach ($permissions as $key =&gt; $value) {
                      $this-&gt;permission[$key] = $value;
                  }
              }
  
              return true;
          } else {
              return false;
          }
      }
  </code></pre>