Welcome Guest, Not a member yet? Register   Sign In
FIXED: Loading a model from inside another model.
#1

[eluser]louis w[/eluser]
In some cases, I need my model to load another model and fetch some info before returning it all to the controller.

The name of the sub-model needs to be dynamic, as it will be coming from the db row.

This is the code I am trying in my model.

Code:
if (!is_object('$this->'.$module.'_model'))
     $this->load->model($module.'_model');

$module_item = $this->{$module.'_model'}->getByID($row[$this->id_field]);

I get this error:
Message: Undefined property: A_model::$b_model (i changed the variable names)


This was developed under PHP5 and I do not care about backwards compatibility with 4.
#2

[eluser]louis w[/eluser]
Oh yes, hello obvious. Nice to meet you.

I forgot that $this-> does not reference the CI instance in a model. Fixed with good old &get;_instance();
#3

[eluser]stuffradio[/eluser]
Glad it worked out!




Theme © iAndrew 2016 - Forum software by © MyBB