Codeigniter Undefined property: xxxx_model::$db only from Model-Record and share programming errors

To add to atno’s answer:

class Xxxx_model extends Model
{
  function XxxxModel() //load->database();
  }

Basically, you are not constructing the class or the parent class Model. If you are on PHP5, you may use __construct(), otherwise you must match the class name exactly, regardless of what alias you load it with in your controller. Example:

class Xxxx_model extends Model
{
  function __construct()
  {
    parent::__construct(); // construct the Model class
  }
}

I may be mistaken (haven’t used 1.x in a while), but if you construct the Model class, there’s no need to load the database if you are using the default connection settings in config/database.php, it should already be loaded for you.

Originally posted 2013-08-31 05:56:37.