Welcome Guest, Not a member yet? Register   Sign In
Calling one model from another model, how?

Hi, How can I load one model from another model? Or one in one function of model call another function of model?

[eluser]The Wizard[/eluser]
yeah surely
load it and access it as normal Smile

You will need to call $this->_assign_libraries() a second time on the first model after it's loaded the second model, otherwise the first second model will not be available to the first.

The FuzzyOne can you give a detailed example?

lets say in Foto_model.php I have function foto_data()

function foto_data($foto_id){


$this->_assign_libraries() ;


Like this???

I sit corrected. Your best bet would be to create a class property which references the $CI Super Object when the model is instantiated:

function __construct()
    $this->CI =& get_instance();

and then you can access other models that way:


I load the model in the constructor and use it normally everywhere else. In your example, $this->load->model('ratings_model') should go in the constructor of foto_model.php. You can use the functions of ratings_model in other functions as you are doing now.

Thank YOU ALLL!!!!

[eluser]Zac G.[/eluser]
Why is it that you still have to load the model manually even if it's loaded in the auto loader?

You don't. What makes you say that?

[eluser]Zac G.[/eluser]
For some reason, it wasn't working for me... I did that and then it worked? I must have made some other change as well...hmmm

Theme © iAndrew 2016 - Forum software by © MyBB