ci如何区分前台和后台 而且只有单入口文件index.php,codeigniter源代码分析之入口文件 index.php...

带注释的源码如下,大致内容就是一些全局定义 目录结构 之类的,然后加载 Codeigniter.php 文件启动CI程序

/*

定义一个运行级别 或 运行环境

后面系统会根据不同的运行环境加载不同的配置文件

development 开启错误报告

test 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.');

}

}

/*

设置 系统的目录名称 and 应用程序的目录名称

*/

$system_path = 'system';

$application_folder = 'application';

/*

覆盖路由:

这里设置的route会覆盖整个系统识别出来的路由segments

*/

// $routing['directory'] = '';

// $routing['controller'] = '';

// $routing['function']= '';

// 改变一些config选项的值

//$assign_to_config['name_of_config_item'] = 'value of config item';

if (defined('STDIN'))

{

chdir(dirname(__FILE__));// 命令行请求模式 切换工作目录到当前文件目录

}

// system path的路径存在 变量 $system_path 设置为绝对路径

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

}

define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));//本文件文件名 index.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.'/');//application_floder 是目录 定义到APPPATH

}

else

{

// 不然 先尝试系统目录中是否存在application_floder

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

总结:

设置 环境ENVIRONMENT 根据这个设置错误级别 error_reporting

可选的 routing 、 assign_to_config

系统路径、应用程序路径 以及对这些路径的检测

一些常量的定义

最后加载CodeIgniter.php

code上值得学习的小细节:

1、18 19行的case没有写break 这样两个case都会执行20行的代码(switch case是按顺序执行的)

2、realpath($path) 会检测path(通过与include_path 、当前工作目录(getcwd()) 进行拼接然后检测路径是否存在)

然后返回绝对路径

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值