Reputation: 7338
How can I load a model into another model in Codeigniter?
Upvotes: 1
Views: 801
Reputation: 7707
You can create «MY_Model» place it on «Application/core». You can afterwards, extend «MY_Model», instead of «CI_Model». Actually, you can have many models on «MY_Model» (using require_once(APPPATH.'/core/some_other_model_name.php')), since «Codeigniter» only suports loading one MY_MODEL. To finish, you can then, on your models, extend from «some_other_model_name». This means that you can actually, inherit from a diferent model, solving your nead on loading a model into model.
This link is for MY_Controller but same principle applies for MY_Model http://codeigniter.com/wiki/MY_Controller_-_how_to_extend_the_CI_Controller/
Hope this helps!
Upvotes: 0
Reputation: 1789
You really shouldn't be loading models into other models. If models share behavior you can use inheritance but loading of models should always be done within the controller.
Upvotes: 3