CodeIgniter - Autoload

只谈情不闲聊 提交于 2019-12-10 20:43:50

问题


I was wondering what the best practices for CodeIgniter's autoload are. Is it bad practice to just autoload everything I might ever need, or is it okay to do so? Does this put more load on the application?

At the moment I'm just autoloading the libraries and helpers I'll be using throughout my application:

$autoload['libraries'] = array('database', 'session', 'parser'); $autoload['helper'] = array('url', 'form');

So I'm basically wondering if this is 'okay' to do or if I should just load some of them when I'm actually going to use them (like the form helper: only load it when I'm actually going to build a form on a page).

Perhaps I'm being a bit too paranoid here, but having read about the 'Ruby way' a lot, I was wondering if there is, maybe, a CodeIgniter way. Thanks in advance!


回答1:


$autoload loads a resource weather you use it or not period

So that in mind I would only autoload what you need all the time, but if I were to input my 2 cents I always use my __construct for this in the top of each controller class file. That way it loads for all pages (functions) in that class and it isn't autoloading even if i don't need it in that class file.




回答2:


You should avoid autoload, because it has an impact on your performance. However think like database connection could be autoloaded if you use it frequently.

Php isn't Java, so loaded application don't persist between requests.



来源:https://stackoverflow.com/questions/5600148/codeigniter-autoload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!