码迷,mamicode.com
首页 > 其他好文 > 详细

CodeIgniter系统流程

时间:2014-07-27 23:16:49      阅读:389      评论:0      收藏:0      [点我收藏+]

标签:des   http   使用   os   文件   数据   io   art   

------------------------------------------------------------------------------------------------------

进入框架入口文件index.php =>

定义应用的当前环境(用于设置错误模式):define(‘ENVIRONMENT‘, ‘development‘);

设置系统文件目录名:$system_path = ‘system‘;

设置应用文件目录名:$application_folder = ‘application‘;  //可自定义

定义当前文件名常量:define(‘SELF‘, pathinfo(__FILE__, PATHINFO_BASEPATH));

定义PHP文件后缀常量:define(‘EXT‘, ‘.php‘);  //这个全局常量不推荐使用

定义系统目录路径常量:define(‘BASEPATH‘, str_replace(‘\\‘, ‘/‘, $system_path));

定义前端控制器文件路径常量:define(‘FCPATH‘, str_replace(SELF, ‘‘, __FILE__));

定义系统目录名常量:define(‘SYSDIR‘, trim(strchr(trim(BASEPATH, ‘/‘), ‘/‘), ‘/‘));

定义应用目录路径常量:define(‘APPPATH‘, BASEPATH.$application_folder.‘/‘);

加载引导文件:require_once BASEPATH.‘core/CodeIgniter.php‘;

---------------------------------@黑眼诗人 <www.chenwei.ws>---------------------------------

进入系统初始化文件CodeIgniter.php =>

define(‘CI_VERSION‘, ‘2.2.0‘);

 

define(‘CI_CORE‘, FALSE);

 

require(BASEPATH.‘core/Common.php‘);   //引入公共函数库文件,包含load_class()等函数

 

require(APPPATH.‘config/‘.ENVIRONMENT.‘/constants.php‘); //引入框架常量文件,文件和目录模式 & 文件流模式

 

set_error_handler(‘_exception_handler‘);   //定义一个自定义错误处理程序以便记录PHP错误

if ( ! is_php(‘5.3‘))
{
  @set_magic_quotes_runtime(0); // Kill magic quotes
}

 

if (isset($assign_to_config[‘subclass_prefix‘]) AND $assign_to_config[‘subclass_prefix‘] != ‘‘)

//设置子类前缀
{
  get_config(array(‘subclass_prefix‘ => $assign_to_config[‘subclass_prefix‘]));
}

 

if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)

//设置一个自由的脚本执行时间限制
{
  @set_time_limit(300);
}

 

$BM =& load_class(‘Benchmark‘, ‘core‘);

//实例化Benchmark基准类,此类使你可以标记点并计算它们之间时间差,内存消耗也可以显示

$BM->mark(‘total_execution_time_start‘);

//基准标记,总执行时间开始:$this->marker[‘total_execution_time_start‘] = microtime();
$BM->mark(‘loading_time:_base_classes_start‘);

//基准标记,加载的时间:$this->marker[‘loading_time:_base_classes_start‘] = microtime();

 

$EXT =& load_class(‘Hooks‘, ‘core‘);    //实例化Hooks钩子类,提供一种不堆砌来扩展基础系统的机制

$EXT->_call_hook(‘pre_system‘);     //调用指定钩子pre_system

 

$CFG =& load_class(‘Config‘, ‘core‘);   //实例化Config配置类,包含管理配置文件的方法

if (isset($assign_to_config))
{
  $CFG->_assign_to_config($assign_to_config);

  //调用Config.php中_assign_to_config方法,保证配置项通过变量被分配 和 重写
}

 

$UNI =& load_class(‘Utf8‘, ‘core‘);    //实例化Utf8类,对UTF-8环境提供支持

 

$URI =& load_class(‘URI‘, ‘core‘);    //实例化URI类,解析URI 和 决定路由

 

$RTR =& load_class(‘Router‘, ‘core‘); //实例化Router路由类,解析URI 和 决定路由

$RTR->_set_routing();        //这个函数确定什么应该是基于URI请求,以及 路由配置文件中设置的路由

if (isset($routing))
{
  $RTR->_set_overrides($routing); //设置控制器覆盖
}

 

$OUT =& load_class(‘Output‘, ‘core‘);  //实例化Output输出类,负责发送最终的输出到浏览器

if ($EXT->_call_hook(‘cache_override‘) === FALSE)
{
  if ($OUT->_display_cache($CFG, $URI) == TRUE)
  {
    exit;               //检测是否有缓存文件,如果有,直接退出当前脚本
  }
}

 

$SEC =& load_class(‘Security‘, ‘core‘);  //实例化Security安全类

 

$IN =& load_class(‘Input‘, ‘core‘);    //实例化Input输入类,为了安全对全局输入数据预处理  

 

$LANG =& load_class(‘Lang‘, ‘core‘);   //实例化Lang语言类

 

require BASEPATH.‘core/Controller.php‘;, //引入 基础控制器类

function &get_instance()
{
  return CI_Controller::get_instance(); //返回静态变量$instance
}

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

  //引入自定义扩展 基础控制器类
}

 

if ( ! file_exists(APPPATH.‘controllers/‘.$RTR->fetch_directory().$RTR->fetch_class().‘.php‘))
{
  show_error(‘Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.‘);
}

include(APPPATH.‘controllers/‘.$RTR->fetch_directory().$RTR->fetch_class().‘.php‘);

//加载本地控制器

 

$BM->mark(‘loading_time:_base_classes_end‘);

//基准标记,加载的时间结束:$this->marker[‘loading_time:_base_classes_end‘] = microtime();

 

安全检查

 

$EXT->_call_hook(‘pre_controller‘);  //调用"pre_controller" hook

 

$BM->mark(‘controller_execution_time_( ‘.$class.‘ / ‘.$method.‘ )_start‘); //基准标记,控制器执行时间标记点

$CI = new $class();  //实例化请求控制器

 

$EXT->_call_hook(‘post_controller_constructor‘); //调用"post_controller_constructor" hook

 

调用请求的方法

 

$BM->mark(‘controller_execution_time_( ‘.$class.‘ / ‘.$method.‘ )_end‘); //基准标记,控制器执行时间结束标记点

 

$EXT->_call_hook(‘post_controller‘);  //调用"post_controller" hook

 

if ($EXT->_call_hook(‘display_override‘) === FALSE)
{
  $OUT->_display();      //发送最后的渲染输出到浏览器
}

 

$EXT->_call_hook(‘post_system‘);  //调用"post_system" hook

 

if (class_exists(‘CI_DB‘) AND isset($CI->db))
{
  $CI->db->close();        //关闭数据库连接
}

-------------------------------------------------------------------------------------------------

CodeIgniter系统流程,布布扣,bubuko.com

CodeIgniter系统流程

标签:des   http   使用   os   文件   数据   io   art   

原文地址:http://www.cnblogs.com/farwish/p/3870712.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!