CodeIgniter 装载类 分析
来源:互联网 发布:淘宝买家修改评论 编辑:程序博客网 时间:2024/04/29 20:14
装载类用于装载元素,这些元素可以是视图文件、辅助函数、模型或者是你自己的文件。(此类由系统自动加载)
一、构造函数:构造函数设置缓冲级别和视图文件、辅助函数等的路径
public function __construct(){$this->_ci_ob_level = ob_get_level();$this->_ci_library_paths = array(APPPATH, BASEPATH);$this->_ci_helper_paths = array(APPPATH, BASEPATH);$this->_ci_model_paths = array(APPPATH);$this->_ci_view_paths = array(APPPATH.'views/'=> TRUE);log_message('debug', "Loader Class Initialized");}
二、初始化装载类方法:此方法初始化已装载的类、已装载的文件、已装载的模型设置为空数组,并加载_ci_autoloader()私有方法加载autoload.php
public function initialize(){$this->_ci_classes = array();$this->_ci_loaded_files = array();$this->_ci_models = array();$this->_base_classes =& is_loaded();$this->_ci_autoloader();return $this;}三、library成员方法:调用时用$this->load->library('class_name', $config, 'object_name')。public function library($library = '', $params = NULL, $object_name = NULL):该方法首先判断$library是否为数组,如果为数组使用foreach递归调用library方法。然后判断$library是否为空或者已在$_base_classes中设置,则返回FALSE。然后判断$params如果不为空且不为数组的话,$params则设置为NULL,最后调用$this->_ci_load_class($library, $params, $object_name)加载
public function library($library = '', $params = NULL, $object_name = NULL){if (is_array($library)){foreach ($library as $class){$this->library($class, $params);}return;}if ($library == '' OR isset($this->_base_classes[$library])){return FALSE;}if ( ! is_null($params) && ! is_array($params)){$params = NULL;}$this->_ci_load_class($library, $params, $object_name);}
四、模型加载public function model($model, $name = '', $db_conn = FALSE):首先判断$model是否为数组,如果为数组使用foreach递归调用model方法,然后判断$model是否为空,如果为空则返回FALSE,然后设置$path为空,判断$model是否有子目录,如果有解析出文件名和路径,接着判断自定义对象名是否为空,如果为空设置为$model,接着判断$name是否在$this->_ci_models中,如果在说明已加载,则return;最后加载和实例化model
public function model($model, $name = '', $db_conn = FALSE){if (is_array($model)){foreach ($model as $babe){$this->model($babe);}return;}if ($model == ''){return;}$path = '';// Is the model in a sub-folder? If so, parse out the filename and path.if (($last_slash = strrpos($model, '/')) !== FALSE){// The path is in front of the last slash$path = substr($model, 0, $last_slash + 1);// And the model name behind it$model = substr($model, $last_slash + 1);}if ($name == ''){$name = $model;}if (in_array($name, $this->_ci_models, TRUE)){return;}$CI =& get_instance();if (isset($CI->$name)){show_error('The model name you are loading is the name of a resource that is already being used: '.$name);}$model = strtolower($model);foreach ($this->_ci_model_paths as $mod_path){if ( ! file_exists($mod_path.'models/'.$path.$model.'.php')){continue;}if ($db_conn !== FALSE AND ! class_exists('CI_DB')){if ($db_conn === TRUE){$db_conn = '';}$CI->load->database($db_conn, FALSE, TRUE);}if ( ! class_exists('CI_Model')){load_class('Model', 'core');}require_once($mod_path.'models/'.$path.$model.'.php');$model = ucfirst($model);$CI->$name = new $model();$this->_ci_models[] = $name;return;}// couldn't find the modelshow_error('Unable to locate the model you have specified: '.$model);}
public function view($view, $vars = array(), $return = FALSE){return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));}
六、装载文件函数:
public function file($path, $return = FALSE){return $this->_ci_load(array('_ci_path' => $path, '_ci_return' => $return));}
七、装载辅助函数:
未完待续。。。
- CodeIgniter 装载类 分析
- CodeIgniter 加密类分析
- CodeIgniter 文件上传类 分析
- CodeIgniter Session类 源代码 分析
- Tomcat6 类装载器分析
- java类装载器分析
- Tomcat5 类装载器分析
- JVM 类装载原理分析-类装载过程
- CodeIgniter 图像处理类 源代码分析
- CodeIgniter 分页类 pagination 源代码分析
- codeigniter源代码分析 -安全类 Security.php
- codeigniter源代码分析 - 钩子类 Hooks.php
- codeigniter源代码分析 - 语言包类 Lang.php
- codeigniter源代码分析 - 编码类 Utf8.php
- codeigniter源代码分析 - 控制器类 Controller.php
- codeigniter源代码分析 - 模型类 Model.php
- codeigniter源代码分析 - 性能分析类 Benchmark.php
- codeigniter源码分析
- hdu3466 Proud Merchants 01背包 排序 dp
- 扩展OSGi控制台,通过web访问操作console,支持3.4、3.6
- 门面模式(facade pattern)
- 非递归实现归并排序
- 4-2java--围炉夜话
- CodeIgniter 装载类 分析
- android 的wifi定位
- 观苹果发布会
- 关于Console.read()和Console.ReadLine()缓冲的问题
- Android教程之MediaStore
- 关于android加载网页的一些问题
- poj1639 Picnic Planning
- Qt自制Model模型
- 黑马程序员-对象的初始化过程