Codeigniter model loading
I开发者_Go百科 have 4 models in codeigniter. I want to load these models in my controller's constructor. Because these have been used many times. Will it effective or make the site slower?
Of course loading code makes the site slower. The more the PHP engine needs to do, the longer it will take to do it. You simply need to ask yourself if loading the model is worth it and how often it is being used.
If your model will be used in every page, put it in the autoloader.
If your model is used in every method (or if it is a small model, in more than one method) of the controller, put it in the constructor.
If your model is only being used in a single method, put it in that method.
The main thing to remember is loading a model will only noticeably slow the site down if it is a gazillion lines line. If it's an average size (less that 4kb) then it really doesn't matter that much.
Have a look at MY_Model to make your model code even more efficient.
If you're gonna be using it everytime, there's an autoload available
精彩评论