Alex Rivera | Logout

Loading and using a codeigniter model from another model

Asked 2011-01-07T19:09:26.023
14

Fellow coders, using codeigniter 1.7.3 can I load a model from the code of another model? I have read many posts theoretical and practical but none gave a final answer.

I have a model that has a function in which i would like to perform an operation on another model. the code is like this:

1: $this->load->model('decision_model');
2: $this->decision_model->hello_decision();  

line 1 works. line 2 fails as follows:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Account_model::$decision_model
Filename: models/account_model.php

I have tried creating simple dumb models, changed function names, giving the model an alias when loading it, etc... no luck

So, theory aside, is this doable?

thanks in advance.

Edit
Report

2 Answers

10

In CI 2.0 you can just call one model directly from another.

answered 2011-07-14T10:04:31.387
1

Try this:

$this->load->model('decision_model');
$CI =& get_instance();
$CI->decision_model->hello_decision(); 
answered 2011-01-07T19:15:37.867

Your Answer