Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter optimization / best place to load models is?

I am working on a large project, made in Codeigniter and I am wondering if there is difference in the performance of an controller dependent, where the required models are loaded.

The question:

  1. should all models be loaded in the constructor,
  2. or in the specific functions that use them,
  3. or partially both of those approaches should be utilized, ie, universally used models throughout the controller loaded in the constructor and those rarely used, to be loaded only when required ?

// Bear in mind, that the application I am working on, has mostly large models, with more then just the insert/update/del functions in them ...

// p.s. I've searched the net on the topic, but failed find anything specific in that subject.

like image 637
someGuyOnTheWeb Avatar asked Oct 04 '22 04:10

someGuyOnTheWeb


1 Answers

Models that will be used consistently on all the site's pages are best autoloaded in the config/autoload.php file. Models that are used throughout all the methods of a controller, should be loaded in that controller's constructor. Models that are only needed in certain methods within a controller, should be loaded inside those methods.

like image 70
Mudshark Avatar answered Oct 13 '22 12:10

Mudshark