CodeIgniter Forums
Call a model from another model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Call a model from another model (/showthread.php?tid=58391)



Call a model from another model - El Forum - 06-09-2013

[eluser]xxIdroxx[/eluser]
Hello, i have a model called "I_Model" and I want to call another model called x_Model.
How do I?


Call a model from another model - El Forum - 06-09-2013

[eluser]jairoh_[/eluser]
Do not call another model from a model. that's not the mvc pattern thing. u just need to call a model in a controller.


Call a model from another model - El Forum - 06-11-2013

[eluser]boltsabre[/eluser]
Depending on the application you may want to have a model extend another model, there is absolutely nothing wrong with that in my opinion.

A classic example is having a base "product" model and from their having several models extending it, perhaps a "buy_product", a "sell_product", a "admin_panel_for_product", a "product_inventory", etc. Your "base" product model would contain all the universal "product" methods that the other child models need.

The above mentioned scenario is no different than having a "MY_Model", except it's on a bit more of a micro/specific scale.

Quote:How do I?
Have you tried looking for the answer on a search engine, this has been answered literally 100's of times already. Try this:
https://www.google.com/search?q=codeigniter+how+to+use+a+model+from+another+model

If you have any problems please next time post your code that is causing the problem and describe the error that you are getting.


Call a model from another model - El Forum - 06-13-2013

[eluser]xxIdroxx[/eluser]
Thanks, I solved the problem!