로딩 과정(공식 소개) :
<span>用户<span>URL<span>请求</span></span></span>
<span>调用应用入口文件(通常是网站的<span>index<span>.<span>php<span>)</span></span></span></span></span>
<span>载入框架入口文件(<span>ThinkPHP<span>.<span>php<span>)</span></span></span></span></span>
<span>记录初始运行时间和内存开销</span>
<span>系统常量判断及定义</span>
<span>载入框架引导类(<span>Think<span>Think<span>)并执行<span>Think<span>::<span>start<span>方法进行应用初始化</span></span></span></span></span></span></span></span>
<span>设置错误处理机制和自动加载机制</span>
<span>调用<span>Think<span>Storage<span>类进行存储初始化(由<span>STORAGE_TYPE<span>常量定义存储类型)</span></span></span></span></span></span>
<span>部署模式下如果存在应用编译缓存文件则直接加载(直接跳转到步骤<span>22<span>)</span></span></span>
<span>读取应用模式(由<span>APP_MODE<span>常量定义)的定义文件(以下以普通模式为例说明)</span></span></span>
<span>加载当前应用模式定义的核心文件(普通模式是<span><span>ThinkPHP<span>/<span>Mode<span>/<span>common<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span></span>
<span>加载惯例配置文件(普通模式是<span><span>ThinkPHP<span>/<span>Conf<span>/<span>convention<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span></span>
<span>加载应用配置文件(普通模式是<span><span>Application<span>/<span>Common<span>/<span>Conf<span>/<span>config<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span></span></span></span>
<span>加载系统别名定义</span>
<span>判断并读取应用别名定义文件(普通模式是<span><span>Application<span>/<span>Common<span>/<span>Conf<span>/<span>alias<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span></span></span></span>
<span>加载系统行为定义</span>
<span>判断并读取应用行为定义文件(普通模式是<span><span>Application<span>/<span>Common<span>/<span>Conf<span>/<span>tags<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span></span></span></span>
<span>加载框架底层语言包(普通模式是<span><span>ThinkPHP<span>/<span>Lang<span>/<span>zh<span>-<span>cn<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span></span></span></span>
<span>如果是部署模式则生成应用编译缓存文件</span>
<span>加载调试模式系统配置文件(<span>ThinkPHP<span>/<span>Conf<span>/<span>debug<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span>
<span>判断并读取应用的调试配置文件(默认是<span><span>Application<span>/<span>Common<span>/<span>Conf<span>/<span>debug<span>.<span>php<span>)</span></span></span></span></span></span></span></span></span></span></span></span>
<span>判断应用状态并读取状态配置文件(如果<span>APP_STATUS<span>常量定义不为空的话)</span></span></span>
<span>检测应用目录结构并自动生成(如果<span>CHECK_APP_DIR<span>配置开启并且<span>RUNTIME_PATH<span>目录不存在的情况下)</span></span></span></span></span>
<span>调用<span>Think<span>App<span>类的<span>run<span>方法启动应用</span></span></span></span></span></span>
<span>应用初始化(<span>app_init<span>)标签位侦听并执行绑定行为</span></span></span>
<span>判断并加载动态配置和函数文件</span>
<span>调用<span>Think<span>Dispatcher<span>::<span>dispatch<span>方法进行<span>URL<span>请求调度</span></span></span></span></span></span></span></span>
<span>自动识别兼容<span>URL<span>模式和命令行模式下面的<span>$_SERVER<span>[<span>'PATH_INFO'<span>]参数</span></span></span></span></span></span></span>
<span>检测域名部署以及完成模块和控制器的绑定操作(<span>APP_SUB_DOMAIN_DEPLOY<span>参数开启)</span></span></span>
<span>分析<span>URL<span>地址中的<span>PATH_INFO<span>信息</span></span></span></span></span>
<span>获取请求的模块信息</span>
<span>检测模块是否存在和允许访问</span>
<span>判断并加载模块配置文件、别名定义、行为定义及函数文件</span>
<span>判断并加载模块的动态配置和函数文件</span>
<span>模块的<span>URL<span>模式判断</span></span></span>
<span>模块的路由检测(<span>URL_ROUTER_ON<span>开启)</span></span></span>
<span>PATH_INFO<span>处理(<span>path_info<span>)标签位侦听并执行绑定行为</span></span></span></span>
<span>URL<span>后缀检测(<span>URL_DENY_SUFFIX<span>以及<span>URL_HTML_SUFFIX<span>处理)</span></span></span></span></span></span>
<span>获取当前控制器和操作,以及<span>URL<span>其他参数</span></span></span>
<span>URL<span>请求调度完成(<span>url_dispatch<span>)标签位侦听并执行绑定行为</span></span></span></span>
<span>应用开始(<span>app_begin<span>)标签位侦听并执行绑定行为</span></span></span>
<span>调用<span>SESSION_OPTIONS<span>配置参数进行<span>Session<span>初始化(如果不是命令行模式)</span></span></span></span></span>
<span>根据请求执行控制器方法</span>
<span>如果控制器不存在则检测空控制器是否存在</span>
<span>控制器开始(<span>action_begin<span>)标签位侦听并执行绑定行为</span></span></span>
<span>默认调用系统的<span>ReadHtmlCache<span>行为读取静态缓存(<span>HTML_CACHE_ON<span>参数开启)</span></span></span></span></span>
<span>判断并调用控制器的<span>_initialize<span>初始化方法</span></span></span>
<span>判断操作方法是否存在,如果不存在则检测是否定义空操作方法</span>
<span>判断前置操作方法是否定义,有的话执行</span>
<span>Action<span>参数绑定检测,自动匹配操作方法的参数</span></span>
<span>如果有模版渲染(调用控制器<span>display<span>方法)</span></span></span>
<span>视图开始(<span>view_begin<span>)标签位侦听并执行绑定行为</span></span></span>
<span>调用<span>Think<span>View<span>的<span>fetch<span>方法解析并获取模版内容</span></span></span></span></span></span>
<span>自动识别当前主题以及定位模版文件</span>
<span>视图解析(<span>view_parse<span>)标签位侦听并执行绑定行为</span></span></span>
<span>默认调用内置<span>ParseTemplate<span>行为解析模版(普通模式下面)</span></span></span>
<span>模版引擎解析模版内容后生成模版缓存</span>
<span>模版过滤替换(<span>template_filter<span>)标签位侦听并执行绑定行为</span></span></span>
<span>默认调用系统的<span>ContentReplace<span>行为进行模版替换</span></span></span>
<span>输出内容过滤(<span>view_filter<span>)标签位侦听并执行绑定行为</span></span></span>
<span>默认调用系统的<span>WriteHtmlCache<span>行为写入静态缓存(<span>HTML_CACHE_ON<span>参数开启)</span></span></span></span></span>
<span>调用<span>Think<span>View<span>类的<span>render<span>方法输出渲染内容</span></span></span></span></span></span>
<span>视图结束(<span>view_end<span>)标签位侦听并执行绑定行为</span></span></span>
<span>判断后置操作方法是否定义,有的话执行</span>
<span>控制器结束(<span>action_end<span>)标签位侦听并执行绑定行为</span></span></span>
<span>应用结束(<span>app_end<span>)标签位侦听并执行绑定行为</span></span></span>
<span>执行系统的<span>ShowPageTrace<span>行为(<span>SHOW_PAGE_TRACE<span>参数开启并且不是<span>AJAX<span>请求)</span></span></span></span></span></span></span>
<span>日志信息存储写入</span>
코드:
1. 항목 파일(색인) .php)
// 检测PHP环境 if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !'); // 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false define('APP_DEBUG',True); // 定义应用目录 define('APP_PATH','./Application/'); // 引入ThinkPHP入口文件 require './ThinkPHP/ThinkPHP.php';
기능 1. 디버깅 모드인지 여부를 설정합니다. (디버깅 모드에서 APP_DEBUG가 True이면 마지막으로 컴파일된 것이 로드되지 않습니다. ~runtime.php에서 개발의 경우 디버깅 모드로 시작하는 것을 권장합니다)
2. APP_PATH 경로를 정의합니다
3. 가장 중요한 것이기도 합니다. 이제부터 복잡하지만 간단한 TP 프레임워크 여정이 정식으로 시작됩니다. 좋은 장비가 없는 사람들도 장비를 가지고 가서 TP를 닦을 수 있습니다. 뼈대.
TP 소스 코드를 따라가며 TP를 전혀 수정하지 않고 페이지가 어떻게 나타나는지 소개하겠습니다
( PS: TP 프레임워크를 배우는 것은 이번이 처음이고 저도 이제 막 시작했습니다. PHP를 배우면서 제 생각을 정리하기 위해 여기에 제 경험을 적고 싶습니다. 혹시 잘못된 점이 있으면 지적해 주세요.
위 내용은 내용의 측면을 포함하여 ThinkPHP32 로딩 과정(1)을 소개하고 있으며, PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.