CodeIgniter 核心代码阅读-入口文件index.php

本文详细解析了index.php作为唯一入口文件的核心逻辑,包括程序运行环境的设定、错误报告级别的配置、系统文件夹路径的初始化等关键步骤,帮助开发者深入理解其工作原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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';




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值