![]() |
Loading Models in Models - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Loading Models in Models (/showthread.php?tid=39449) |
Loading Models in Models - El Forum - 03-10-2011 [eluser]axiom82[/eluser] Developers debate that MVC does/doesn't allow loading of models in models. I have run into technical situations where loading one model into another is necessary. Such as in the case were one model needs to query for data that another model has already "clearly" standardized in an API. Not only does loading one model into another keep coding lean, recoding identical functions or identical queries for two models is absurd. You want models in models, it makes sense. Here you go. Place this at the end of /system/libraries/Model.php::model(). Now you can use $this->load->model() inside of models. Code: if (floor(phpversion()) >= 5) Loading Models in Models - El Forum - 03-10-2011 [eluser]bubbafoley[/eluser] you can already load models from other models: Code: <?php Loading Models in Models - El Forum - 03-10-2011 [eluser]InsiteFX[/eluser] And besides you should not hack the Model core class file! Extended it with a MY_Model InsiteFX Loading Models in Models - El Forum - 03-11-2011 [eluser]axiom82[/eluser] I stand corrected on both accounts. You can load models into models and you should extend the core with MY_Model. Thanks guys! |