title: CodeIgniter: Undefined property $db
body: <p>In CodeIgniter 3.1.3 I extended CI_Model in application/core/MY_Model.php:</p>
  
  <pre><code>class MY_Model extends CI_Model {
  
      public function __construct($id = NULL) {
          parent::__construct();
          $this-&gt;load($id);
      }
  
      public function load($id) {
          $this-&gt;db-&gt;where('id', $id);
          $this-&gt;db-&gt;limit(1);
          $query = $this-&gt;db-&gt;query($this-&gt;_table);
          if ($row = $query-&gt;result()) {
              // @todo Process results
          }
          // Free the resources.
          $query-&gt;free_result();
      }
  
  }
  </code></pre>
  
  <p>My User_model looks like this:</p>
  
  <pre><code>class User_model extends MY_Model {
  
      public function __construct($id = NULL) {
          parent::__construct($id);
      }
  
  }
  </code></pre>
  
  <p>I also extended the CI_Controller in application/core/MY_Controller as follows:</p>
  
  <pre><code>class MY_Controller extends CI_Controller {
  
      public function __construct() {
          parent::__construct();
          $this-&gt;load-&gt;model('User_model');
      }
  }
  </code></pre>
  
  <p>I autoloaded the database connection in application/config/autoload.php as:</p>
  
  <pre><code>$autoload['libraries'] = array('database');
  </code></pre>
  
  <p>Without loading the User_model in the controller I was able to run migrations, so the database connection is configured correctly. But when I added $this->load->model('User_model') I get the error "Undefined property: User_model::$db".</p>
  
  <p>If I let User_model extend CI_Model it runs without errors and with a var_dump in the homepage's controller it shows that the database is autoloaded correctly. But as soon as I put MY_Model in between, the database class is undefined in the model and also $this->load in the model returns NULL, so it appears the model is not properly constructed.</p>
  
  <p>I can only imagine this to be a very small mistake, but I've been staring at it for hours with several breaks in between and I just don't see it. Can anyone else help me?</p>