[eluser]conord[/eluser]
EDIT: As suspected this was user-error. I had inserted some code in the system/core/model.php code that overwrote the default object. Removed code and database access has been restored. Leaving thread here in case same happens to someone else.
I'm still learning the ins-and-outs with CI and was working with models. Initially, I created a model and called it from a controller - but not the matching controller (eg: controller was Users and model was Stores). When I tried a DB query in the Stores model, got the "calling member function on non-object" error. BTW, the database library should be auto-loaded via the config.
I figured this was due to where I called the model from, so I added $CI->get_instance(); and $this->db = $CI->load('database'); Everything fixed.
Recently though, I created a base model (My_Model.php) which extends CI_Model. I then extend MY_Model in my Users model. Each class calls parent::_constructor() so I thought I should have access to the full CI instance through $this. That doesn't seem to be the case.
Code:
Code:
class MY_Model extends CI_Model
{
private $_errors = array();
public function __construct()
{
parent::__construct();
}
..snip...
}
Code:
<?php
class Usersmodel extends MY_Model
{
private $_error;
private $_user_table = "users";
public function __construct()
{
parent::__construct();
}
public function get_all_users($order_by = "username ASC")
{
$this->db->order_by($order_by);
if (false === $result = $this->db->get())
{
$this->set_error();
return false;
}
return $result->result_array();
}
..snip..
}
The error is happening at the $this->db->order_by() line.
TLR: Don't have access to $this->db inside my models.[/b]