最近在学习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 */