【CI】阅读源码整理(二)Loader类

CI官方解释:

加载器类

加载器,顾名思义,是用于加载元素的,加载的元素可以是库(类),视图文件 , 驱动器 ,辅助函数 , 模型 或其他你自己的文件。

在开发过程中,一般都会继承框架Controller文件,该文件位置为system\core\Controller.php。

在该文件的__construct方法:

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的相关方法。

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()            ======》加载驱动文件

转载于:https://my.oschina.net/u/3268486/blog/3029136

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值