CI官方解释:php
加载器,顾名思义,是用于加载元素的,加载的元素能够是库(类),视图文件 , 驱动器 ,辅助函数 , 模型 或其余你本身的文件。html
在开发过程当中,通常都会继承框架Controller文件,该文件位置为system\core\Controller.php。数据库
在该文件的__construct方法:bootstrap
public function __construct() { self::$instance =& $this; // Assign all the class objects that were instantiated by the // bootstrap file (CodeIgniter.php) to local class variables // so that CI can run as one big super object. foreach (is_loaded() as $var => $class) { $this->$var =& load_class($class); } $this->load =& load_class('Loader', 'core'); $this->load->initialize(); log_message('info', 'Controller Class Initialized'); }
$this->load =& load_class('Loader', 'core');框架
代表在文件运行的时候会自动加载Loader类,因此能够直接在自定义控制器中使用 $this->load的相关方法。ide
Loader类分装了如下方法:函数
library() ====》加载lib文件 model() ====》加载model文件 database() ====》加载db文件 dbutil() =====》官方解释,感受是除了加载默认数据库外的其余数据库 dbforge() ====》加载Db文件,可用于操做表结构 view() =====》加载view文件 file() =====》加载文件 helper() =====》该方法用于加载辅助函数文件,其中 file_name 为加载的文件名,不带 _helper.php 后缀。 helpers() =====》An alias for the helper() method in case the developer has written the plural form of it.该方法的注释内容,防止开发人员建立复数形式 language() ======》加载语言包文件 config() ======》加载配置文件,除了在config/autoload.php中加载过的文件 driver() ======》加载驱动文件