zarpio
zarpio

Reputation: 7338

How to load Model into Model in Codeigniter?

How can I load a model into another model in Codeigniter?

Upvotes: 1

Views: 801

Answers (2)

punkbit
punkbit

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

Ken Struys
Ken Struys

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

Related Questions