问题
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