[eluser]axiom82[/eluser]
Developers debate that MVC does/doesn't allow loading of models in models. I have run into technical situations where loading one model into another is necessary. Such as in the case were one model needs to query for data that another model has already "clearly" standardized in an API. Not only does loading one model into another keep coding lean, recoding identical functions or identical queries for two models is absurd.
You want models in models, it makes sense. Here you go. Place this at the end of /system/libraries/Model.php::model(). Now you can use $this->load->model() inside of models.
Code:
if (floor(phpversion()) >= 5)
{
$this->load =& load_class('Loader');
$this->load->_ci_autoloader();
}
else
{
$this->_ci_autoloader();
// sync up the objects since PHP4 was working from a copy
foreach (array_keys(get_object_vars($this)) as $attribute)
{
if (is_object($this->$attribute))
{
$this->load->$attribute =& $this->$attribute;
}
}
}