最近在學習CI框架,自己在按照代碼執行順序閱讀源碼。做了一些筆記。與其自己珍藏不如拿出來和大家分享
本人并非大牛,是一名處于成長初期的phper,難免有錯誤的地方。還希望大家能給予指正。
我的CI版本是2.1.3
csdn好像不能上傳文件,我就講代碼放在筆記下面了。
如果覺得能對您有一些可以經常來看,我會不定期更新。知道讀完CI源碼
程序入口:
1、? 應用程序環境設置development? testing?production? 可以設置這三種環境
2、? 對不同的環境應用不同的錯誤級別
3、? 設置系統文件夾名
4、? 設置應用程序文件夾名
5、? 設置默認控制器(這里被注釋掉了,如果想設置直接開啟)
6、? 設置自定義配置
7、? 增強system path的可靠性
a)????????設置當前目錄保證正確的請求
b)????????保證目錄后面有/
c)????????判斷當前系統路徑是否存在
8、? 開始設置主路徑常量
SELF ?????????????????? 當前文件的路徑
EXT? ????????????????? 文件擴展名
BASEPATH????????? 系統路徑
FCPATH?????????????? 前端控制器路徑
SYSDIR??????????????? 系統文件夾路徑
APPPATH??????????? 應用程序文件夾路徑
9、調用BASEPATH.'core/CodeIgniter.php'文件進入系統引導程序
~~~
<?php
/*
*---------------------------------------------------------------
* APPLICATION ENVIRONMENT
*---------------------------------------------------------------
*
* You can load different configurations depending on your
* current environment. Setting the environment also influences
* things like logging and error reporting.
*
* This can be set to anything, but default usage is:
*
* development
* testing
* production
*
* NOTE: If you change these, also change the error_reporting() code below
*
*/
define('ENVIRONMENT', 'development');
/*
*---------------------------------------------------------------
* ERROR REPORTING
*---------------------------------------------------------------
*
* Different environments will require different levels of error reporting.
* By default development will show errors but testing and live will hide them.
*/
if (defined('ENVIRONMENT'))
{
switch (ENVIRONMENT)
{
case 'development':
error_reporting(E_ALL);
break;
case 'testing':
case 'production':
error_reporting(0);
break;
default:
exit('The application environment is not set correctly.');
}
}
/*
*---------------------------------------------------------------
* SYSTEM FOLDER NAME
*---------------------------------------------------------------
*
* This variable must contain the name of your "system" folder.
* Include the path if the folder is not in the same directory
* as this file.
*
*/
$system_path = 'system';
/*
*---------------------------------------------------------------
* APPLICATION FOLDER NAME
*---------------------------------------------------------------
*
* If you want this front controller to use a different "application"
* folder then the default one you can set its name here. The folder
* can also be renamed or relocated anywhere on your server. If
* you do, use a full server path. For more info please see the user guide:
* http://codeigniter.com/user_guide/general/managing_apps.html
*
* NO TRAILING SLASH!
*
*/
$application_folder = 'application';
/*
* --------------------------------------------------------------------
* DEFAULT CONTROLLER
* --------------------------------------------------------------------
*
* Normally you will set your default controller in the routes.php file.
* You can, however, force a custom routing by hard-coding a specific
* controller class/function here. For most applications, you
* WILL NOT set your routing here, but it's an option for those 那些
* special 特殊 instances where you might 可能 want to override the standard 標準
* routing in a specific 明確的 front 前面 controller that shares a common CI installation.
*
* IMPORTANT: 重要的 If you set the routing here, NO OTHER controller will be
* callable. 可贖回的 In essence,本質 this preference 偏好、傾向、優先權 limits 范圍、限制
* your application to ONE specific controller.
* Leave 許可、離開、留下 the function name blank空白,消失 if you need
* to call functions dynamically 動態的 via 通過 the URI.
*
* Un-comment the $routing array below 在下面 to use this feature 特色,特寫,起重要作用
*
*/
// The directory name, relative 相關的 to the "controllers" folder. Leave blank
// if your controller is not in a sub-folder 代替-文件夾 within 在。。。之內
// the "controllers" folder
// $routing['directory'] = '';
// The controller class file name. Example: Mycontroller
// $routing['controller'] = '';
// The controller function you wish 希望 to be called.
// $routing['function'] = '';
/*
* -------------------------------------------------------------------
* CUSTOM 習慣、定制的、自定義的 CONFIG VALUES
* -------------------------------------------------------------------
*
* The $assign_to_config array below will be passed 通過 dynamically to the
* config class when initialized.初始化 This allows you to set custom config
* items or override any default config values found in the config.php file.
* This can be handy 方便的 as it permits 許可 you to share one application between
* multiple front controller files, with each 每各 file containing 包含 different
* config values.
*
* Un-comment the $assign_to_config array below to use this feature
*
*/
// $assign_to_config['name_of_config_item'] = 'value of config item';
// --------------------------------------------------------------------
// END OF USER CONFIGURABLE 可配置的 SETTINGS. DO NOT EDIT BELOW THIS LINE
// end of 最終 user configurable settings . do not edit below this line
// --------------------------------------------------------------------
/*
* ---------------------------------------------------------------
* Resolve 決定 the system path for increased 增強的、增加 reliability 可靠性
* ---------------------------------------------------------------
*/
// Set the current directory correctly 正確的 for CLI requests 請求
if (defined('STDIN'))
{
chdir(dirname(__FILE__));
}
if (realpath($system_path) !== FALSE)
{
$system_path = realpath($system_path).'/';
}
// ensure 保證 there's a trailing 后面的 slash 斜杠
$system_path = rtrim($system_path, '/').'/';
// Is the system path correct?
if ( ! is_dir($system_path))
{
exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
}
/*
* -------------------------------------------------------------------
* Now that we know the path, set the main path constants 常量
* -------------------------------------------------------------------
*/
// The name of THIS file
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
// The PHP file extension 擴展
// this global constant is deprecated.不贊成 棄用
define('EXT', '.php');
// Path to the system folder
define('BASEPATH', str_replace("\\", "/", $system_path));
// Path to the front controller (front controller)前端控制器 (this file)
define('FCPATH', str_replace(SELF, '', __FILE__));
// Name of the "system folder"
define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/'));
// The path to the "application" folder
if (is_dir($application_folder))
{
define('APPPATH', $application_folder.'/');
}
else
{
if ( ! is_dir(BASEPATH.$application_folder.'/'))
{
exit("Your application folder path does not appear to be set correctly. Please open the following file and correct this: ".SELF);
}
define('APPPATH', BASEPATH.$application_folder.'/');
}
/*
* --------------------------------------------------------------------
* LOAD THE BOOTSTRAP 引導程序 FILE
* --------------------------------------------------------------------
*
* And away we go... 和我們走
*
*/
require_once BASEPATH.'core/CodeIgniter.php';
/* End of file index.php */
/* Location: ./index.php */
~~~