CodeIgniter - 自动加载 [英] CodeIgniter - Autoload

查看:115
本文介绍了CodeIgniter - 自动加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道CodeIgniter的自动加载的最佳做法是什么。只是自动加载我可能需要的一切,这是不好的做法,还是可以这样做?这会给应用程序带来更多的负担吗?



目前我只是自动加载库和助手,我将在整个应用程序中使用:



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



m基本上想知道这是否好做,或者如果我真的要加载一些他们,当我实际要使用它们(像窗体助手:只加载它,当我实际上要建立一个表单上页)。



也许我在这里有点太偏执了,但是经常阅读Ruby的方法,我想知道是否还有CodeIgniter方法。提前感谢!

解决方案

$ autoload载入您使用或不是周期的资源天气 p>

所以记住我只会自动加载你需要的所有时间,但如果我输入2美分,我总是使用我的__construct在每个控制器的顶部类文件。这样,它加载该类中的所有页面(函数),并且它不是自动加载,即使我不需要它在该类文件。


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!

解决方案

$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.

这篇关于CodeIgniter - 自动加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆