×
新网 > 虚机资讯 > 正文

CI框架代码体会

  • 作者:未知
  • 来源:
  • 2018-03-05 01:18:48

本文主要记录一些自己在浏览CI代码时候的一些体会,并不分析CI的使用。首先的一点就是, 已加载类在codeigniter, controller,model中的通用,这使得CI的controller和model功能丰富。

本文主要记录一些自己在浏览CI代码时候的一些体会, 并不分析CI的使用。

timg (4).jpg

一 、 首先的一点就是, 已加载类在codeigniter, controller, model中的通用, 这使得CI的controller和model功能丰富。

体现在Controller中的构造函数中:

foreach (is_loaded() as $var => $class)
{
$this->$var =& load_class($class); //将加载过的载入
}

$this->load =& load_class(\'Loader\', \'core\');

$this->load->initialize(); // 加载autoload配置的库类

体现在model中:

function __get($key)
{
$CI =& get_instance();
return $CI->$key;
}

方法中

通过这样的操作, 是的CI的controller, model 功能丰富。

 

2、 CI允许扩展核心系统类:

在/system/core/common 中:

load_class 中有如下几行:

foreach (array(APPPATH, BASEPATH) as $path) { if (file_exists($path.$directory.\'/\'.$class.\'.php\')) { $name = $prefix.$class; if (class_exists($name) === FALSE) { require($path.$directory.\'/\'.$class.\'.php\'); } break; } } // Is the request a class extension? If so we load it too if (file_exists(APPPATH.$directory.\'/\'.config_item(\'subclass_prefix\').$class.\'.php\')) { $name = config_item(\'subclass_prefix\').$class; if (class_exists($name) === FALSE) { require(APPPATH.$directory.\'/\'.config_item(\'subclass_prefix\').$class.\'.php\'); } }

对于Controller的重写体现在(system/core/codeingiter):

require BASEPATH.\'core/Controller.php\';

function &get_instance()
{
return CI_Controller::get_instance();
}

if (file_exists(APPPATH.\'core/\'.$CFG->config[\'subclass_prefix\'].\'Controller.php\'))
{
require APPPATH.\'core/\'.$CFG->config[\'subclass_prefix\'].\'Controller.php\';
}

这可以满足自己的业务逻辑的修改, 例如可以在自己扩展出来的controller中加一些权限控制的操作等等。

 

3、 Loader类也被controller加载了(依附在controller上的model也享受利益), 通过这个类,可以实现各种功能库的加载

 

4、 可以挂载多个系统

根据业务需求可能需要开发多个系统, 可以在index.php , 根据业务类型, 修改index.php

$applocation_folder参数

例如: 可以在配置虚拟主机的时候, 设置service_name 等等 当然这只是一种思路

(待续)

对CI的common文件比较纠结的就是, 在整个框架代码中, 突然出来一个这个理的方法还是有点让人不知所措, 觉得应该在方法的前面加上一个common_之类的标记, 然后自己也可以在里面创建一个自己的同类文件, 在方法的前面标记上my_,, 可能会更加清晰一些

 

  • 相关专题

免责声明:本文内容由互联网用户自发贡献自行上传,本网站不拥有所有权,也不承认相关法律责任。如果您发现本社区中有涉嫌抄袭的内容,请发送邮件至:operations@xinnet.com进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。

免费咨询获取折扣

Loading