I have two models, first one is dependent on the second one, and I need to call methods from the second one in the first one's constructor.
So far I have this:
user
class User extends CI_Model {
protected $_attributes = array();
function __construct() {
parent::__construct();
$this->load->model('musers');
foreach($this->musers->GetProfile() as $key => $val) {
$this->_attributes[$key] = $val;
}
}
function __set($key, $val) {
return $this->_attributes[$key] = $val;
}
function __get($key) {
return $this->_attributes[$key];
}
}
I have put this model in the autoload config file and here's what I get:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: load
Filename: models/user.php
Line Number: 20
Fatal error: Call to a member function model() on a non-object in path\to\models\user.php on line 9
There's also something strange - the first error (notice) refers to line return $this->_attributes[$key]; while it surely should reference line $this->load->model('musers');.
I have tried loading model musers in autoload before the user model, but nothing helps. I have tried searching for this, but could not formulate the query well, I'm sure there are solutions to my problem.
As I understand this is because the constructor of the second model is called before CodeIgniter manages to load the loader class itself, but that's pretty odd.