您好,欢迎访问一九零五行业门户网

tp流程

tp的流程代码 很多 慢慢看
tp已经用了很久了。可是使用起来是很顺利。可是源码已经运行流程都不了解。今天了解下thinkphp的运行流程。
首先是框架的目录
/index.php //项目入口文件
/thinkphp/thinkphp.php //框架入口文件
common 框架公共文件目录(函数库)
thinkphp/common/runtime.php //框架初次运行文件
thinkphp/common/common.php //框架基础函数库
thinkphp/common/functions.php //标准模式公共函数库
conf 框架配置文件目录
thinkphp/conf/convention.php //惯例配置文件,系统默认配置小于项目配置
thinkphp/conf/debug.php //默认的调试模式配置文件
lang 框架系统语言目录
lib 系统核心基类库目录
thinkphp/core/think.class.php //入口文件(设置异常和错误处理机制、注册系统自动加载机制、预编译当前项目、加载框架惯例配置文件)
thinkphp/lib/core/log.class.php, // 日志处理类
thinkphp/lib/core/dispatcher.class.php, // url调度类
thinkphp/lib/core/app.class.php, // 应用程序类
thinkphp/lib/core/action.class.php, // 控制器类
thinkphp/lib/core/view.class.php, // 视图类
tpl 系统模板目录
thinkphp/tpl/default_index.tpl //测试模块的模板
thinkphp/tpl/dispatch_jump.tpl //页面提示的模板
thinkphp/tpl/page_trace.tpl //页面trace信息的模板
thinkphp/tpl/think_exception.tpl //系统错误信息的模板
extend 框架扩展目录
apperror()注册为错误处理方法
set_exception_handler(array('think','appexception')); //将$this->appexception()注册为异常处理函数
// 注册autoload方法
spl_autoload_register(array('think', 'autoload'));//将$this->autoload()注册为__autoload()方法
//[runtime]
think::buildapp(); // 读取配置信息 预编译项目
//[/runtime]
// 运行应用
app::run();
return ;
}
//#61-124 读取配置信息 预编译项目
static private function buildapp() {
// /thinkphp/conf/convention.php 读取系统配置,读取项目配置 /项目/conf/conf.php 合并配置
//加载语言包(可能是支持多语言的,目前没用到过)
//加载模式系统行为定义(没看明白)
//读取核心编译文件列表 (使用compile()函数,将所有核心类及函数、自定义类库压入到$compile变量中,等待编译~runtime.php)
(
thinkphp/common/functions.php, // 标准模式函数库
thinkphp/lib/core/log.class.php, // 日志处理类
thinkphp/lib/core/dispatcher.class.php, // url调度类
thinkphp/lib/core/app.class.php, // 应用程序类
thinkphp/lib/core/action.class.php, // 控制器类
thinkphp/lib/core/view.class.php, // 视图类
);
// thinkphp/common/common.php //加载项目公共文件(函数库)
// 项目/conf/alias.php 加载项目别名定义(项目自定义类库,用别名导入的方式引入的自定义类库)
// 如果是调试模式,加载系统默认的配置文件thinkphp/conf/debug.php的默认调试配置,如果项目自己定义了 项目/conf/debug.php则读取项目调试配置
// 最后如果是部署模式 使用build_runtime_cache($compile); 创建编译缓存,将$compile变量写入到项目/runtime/~runtime.php文件中
// 欧克至此该引入的文件全部引入完成,下面讲解控制器篇
// 最后的最后我们来回顾一下我们加载了些什么东西到程序中来
/*
* 1、thinkphp/common/functions.php, // 标准模式函数库
* 2、thinkphp/lib/core/log.class.php, // 日志处理类
* 3、thinkphp/lib/core/dispatcher.class.php, // url调度类
* 4、thinkphp/lib/core/app.class.php, // 应用程序类
* 5、thinkphp/lib/core/action.class.php, // 控制器类
* 6、thinkphp/lib/core/view.class.php, // 视图类
* 7、thinkphp/common/common.php //加载项目公共文件(函数库)
* 8、项目/conf/alias.php 加载项目别名定义(项目自定义类库,用别名导入的方式引入的自定义类库)
* 9、thinkphp/conf/debug.php的默认调试配置
*/
}
/*
* 加载了半天文件再在来真的了,正式进入程序运行 app::run();
* /thinkphp/lib/core/app.class.php //应用程序类 执行应用过程管理
* 这里是整个程序的入口,我们要跳着读,首先跳入app::init();
* 最后一步跳入app::exec();
*/
// #148-164 运行应用实例 入口文件使用的快捷方法
static public function run() {
// 项目初始化标签
tag('app_init');
app::init();
// 项目开始标签
tag('app_begin');
// session初始化
session(c('session_options'));
g('inittime');
//执行应用程序
app::exec();
// 项目结束标签
tag('app_end');
// 保存日志记录
if(c('log_record')) log::save();
return ;
}
// #36-76 应用程序初始化
static public function init() {
// load_ext_file(); 加载动态项目公共文件和配置
// url调度 dispatcher::dispatch(); //进入thinkphp/lib/core/dispatcher.class.php dispatch()方法,进行url参数常量赋值
// 如果有分组,include 分组配置与函数文件
// 获取模板主题名称 $templateset = c('default_theme');
// 定义模板路径常量 define('theme_path', tmpl_path.$group.(theme_name?theme_name.'/':''));
// 定义模板路径常量 define('app_tmpl_path',.'/'.app_name.(app_name?'/':'').basename(tmpl_path).'/'.$group.(theme_name?theme_name.'/':''));
// 定义模板文件的位置 c('template_name',theme_path.module_name.(defined('group_name')?c('tmpl_file_depr'):'/').action_name.c('tmpl_template_suffix'));
// 定义模板文件缓存的位置 c('cache_path',cache_path.$group);
}
// #89-138 执行应用程序
static public function exec() {
// 安全检测,模块名必须是英文和数字组成,且英文为首
// 检测通过 实例化 控制器 $module = a($group.module_name);
// 检测如果定义了__hack_module()扩展,则遇到当前模块不存在时会被接管,优先级大于空模块emptyaction
// 检测如果否定义空模块emptyaction,则遇到不存在模块时调用emptyaction模块
// 检测前置后置方法(_before_、_after_) method_exists($module,'_before_'.$action),如果有则执行 call_user_func(array(&$module,'_before_'.$action));
// 亮点在这里,至此url解析完成了,跳转到 某某模块下的某某方法 执行当前操作 call_user_func(array(&$module,$action));
}
/*
* 接上一步,跳入app::init();后,我们发现需要跳入dispatcher::dispatch();url调度类中进行url参数常量赋值,下面带你进入disppatcher::dispatch方法中进行常量赋值
* thinkphp内置的dispatcher类 只提供了一个公共的静态方法dispatch()方法作为接口,本方法将路由变量压入到常量中,供后面的action类使用
* 完成url解析、路由和调度
* thinkphp/lib/core/dispatcher.class.php
* 完成后跳回到app::init();
*/
//#36-153 url映射到控制器
static public function dispatch() {
//c('url_model');读取url模式
//将模块提取到module_name全局变量中,将动作提取到action_name全局变量中,将参数
// $paths = explode($depr,trim($_server['path_info'],'/'));//解析path_info
//$var[c('var_module')] = array_shift($paths);//提取模块
// $var[c('var_action')] = array_shift($paths);//提取方法
// $_get = array_merge($var,$_get);//重写$_get
// pathinfo常量 /article/220
// 控制器常量 define('module_name',self::getmodule(c('var_module')));
// 方法常量 define('action_name',self::getaction(c('var_action')));
// url常量 define('/index.php/article/220.html',strip_tags($_server['request_uri']));
// 当前项目地址常量 define('',strip_tags(php_file));
// 当前操作地址常量 define('/index/show_article',/index.$depr.action_name);
// $_request = array_merge($_post,$_get); $_request重写
}
ad:真正免费,域名+虚机+企业邮箱=0元
其它类似信息

推荐信息