------------------------------------------------------------------------------------------------------
進入框架入口文件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.farwish.com>---------------------------------
進入系統初始化文件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_ //設置子類前綴{ 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(); //關閉數據庫連接} -------------------------------------------------------------------------------------------------
新聞熱點
疑難解答