[eluser]GSV Sleeper Service[/eluser]
What's the correct way to load libraries and (other) models from within a model?
The user guide is pretty vague about this.
a confusing example below
Code:
class Quotes_model extends Model {
...
function save_quote()
{
$this->load->model('address_model'); //no error raised
$this->address_model->get_primary_address(); //Fatal error: Call to a member function get_primary_address() on a non-object
echo $this->session->userdata('example_session_var'); //works fine
// CI get instance method below
$CI =& get_instance();
$CI->load->model('address_model');
$CI->address_model->get_primary_address(); //this works fine
}
}
so, why does '$this' in a model sometimes refer to the CI superclass (sessions, input etc), but in other cases I have to use get_instance()?