CodeIgniter 核心代碼閱讀-入口文件index.php

index.php----唯一入口文件

<?php


//定義程序運行環境,可選項:development、testing、production
define('ENVIRONMENT', 'development');

//根據程序運行環境,設置錯誤報告級別
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_path = 'system';

//應用程序文件夾路徑
$application_folder = 'application';


//當一CLI方式運行程序時,設置當前目錄
if (defined('STDIN'))
{
	chdir(dirname(__FILE__));
}

if (realpath($system_path) !== FALSE)
{
	$system_path = realpath($system_path).'/';
}

//確保路徑後有'/'
$system_path = rtrim($system_path, '/').'/';

//確保系統路徑正確
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));
}

//定義系統路徑常量

//當前文件的名稱,即index.php,即入口文件名稱
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));

//php文件後綴
//此全局常量已經被棄用
define('EXT', '.php');

//系統文件夾路徑
define('BASEPATH', str_replace("\\", "/", $system_path));

//當前文件的路徑
define('FCPATH', str_replace(SELF, '', __FILE__));

//系統文件夾名稱
define('SYSDIR', trim(strrchr(trim(BASEPATH, '/'), '/'), '/'));


//應用程序文件夾路徑
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.'/');
}

//啓動程序
require_once BASEPATH.'core/CodeIgniter.php';




發佈了28 篇原創文章 · 獲贊 9 · 訪問量 25萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章