CodeIgniter Forums
Model Loading Optimization - 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: Model Loading Optimization (/showthread.php?tid=10576)



Model Loading Optimization - El Forum - 08-05-2008

[eluser]Unknown[/eluser]
I'm building my first CI site, and in the spirit of CI's lightweight mantra, I'm trying to decide what is the best way to load my models. Here's the situation: I've got several types of pages, and to create my navigation dynamically, I'm loading the models for each page type based on information in my database. That results in a call to
Code:
$this->load->model($modelname)
for every navigation item on a page (there are between 8 and 12 on each). However, there is no guarantee that each page will utilize all potential models.

So my question boils down to this: Is it more efficient to call
Code:
$this->load->model($modelname)
repeatedly (which does just return if the model is already loaded -- I checked the source), or would it be more efficient to autoload all page models
Code:
$autoload['model'] = array('page', 'event', etc...)
(there would be about 5) with every request?

Thanks for any input!


Model Loading Optimization - El Forum - 08-05-2008

[eluser]Colin Williams[/eluser]
If you aren't running queries from your Model constructors, I don't see how awful loading 5 files and instantiating 5 classes could be. Easy enough to test/benchmark.