phpcodeignitermodelcodeigniter-2

"Call to a member function get() on a non-object" error after updating to Codeigniter2


I updated to CI 2.0 now my models stopped working.I used

parent::__construct();

And I defined the class correctly extends CI_Model but even using a simple get all

$query = $this->db->get('mytable');

Returns an error

Call to a member function get() on a non-object in models\crudModel.php on line 13

I'm sure its related to the update since they worked fine before.


Solution

  • It sounds very much like you are not loading the database library - have you got it in your config/autoload.php? It is sensible to autoload it if you use the database library in all your controllers:

    $autoload['libraries'] = array( 'database' );