参见index.php说明文档,则应用程序主要调用文件流程为:
* Overview of flow
* <ul>
* <li>Load application_top.php - see {@tutorial initsystem}</li>
* <li>Set main language directory based on $_SESSION['language']</li>
* <li>Load all *header_php.php files from includes/modules/pages/PAGE_NAME/</li>
* <li>Load html_header.php (this is a common template file)</li>
* <li>Load main_template_vars.php (this is a common template file)</li>
* <li>Load on_load scripts (page based and site wide)</li>
* <li>Load tpl_main_page.php (this is a common template file)</li>
* <li>Load application_bottom.php</li>
* </ul>
1.系统配置及初始化
2.配置当前语言目录
3.加载模型文件header_php.php
4.加载头部模板html_header.php(<head>)
5.加载主要页面部分模型main_template_vars.php和模板tpl_[main_page]_defaule.php
6.加载onload脚本
7.加载通用模板tpl_main_page.php(<body>)
8.系统清理收尾工作
具体说明如下:
首先,调用application_top.php进行初始化工作,比如加载配置文件include(’includes/configure.php’);,如果系统没检测到该文件的存在则会尝试调用安装文件。然后它会自动遍历include/extra_configures下的配置文件并包含进来。
在加载了系统配置文件以后接下来是一个非常重要的文件,这也导致了zencart和oscommerce感觉上很大不同的原因,首先调用一个文件require(’includes/initsystem.php’); 在 initsystem.php中最先加载include/auto_loaders/config.core.php,config.core.php是一个二维数组$autoLoadConfig,即以数组的形式保存文件的信息供后面文件调用,然后系统会接着加载完 include/auto_loaders目录下所有文件名匹配$loaderPrefix(默认为config)的文件。
上面程序执行完以后就是加载自动执行程序了require(’includes/autoload_func.php’);在这里它会遍历$autoLoadConfig数组,它最终执行的效果会包含所有必须用到的函数或者类的定义,还有变量的初始化,config.core.php里面的注释比较清楚比如
$autoLoadConfig[0][] = array(’autoType’=>’class’,’loadFile’=>’class.base.php’);
在autoload_func.php里面执行完以后的效果就是require(DIR_WS_CLASSES . ‘class.base.php’),大部分的初始化化工作是通过包含init_includes目录下的文件来实现的,如:
$autoLoadConfig[110][] = array(’autoType’=>’init_script’,’loadFile’=> ‘init_templates.php’);
它在执行完autoload_func.php文件后就已经加载了init_includes目录下的init_templates.php文件。
接下来,介绍下zencart是怎么根据摸版把内容显示出来的。
(1) 包含includes/modules/pages/[main_page]/目录下,以header_php开头的所有php文件。(通常只有header_php.php文件)(可视为模型Module文件)
(2) 包含includes/templates/..目录下的html_header.php文件。(通常为includes/templates/template_default/common/html_header.php文件,详见 http://blog.youkuaiyun.com/phpxin123/article/details/7654730 中get_template_dir()的例子释义)
(3) 首先检查includes/templates/..目录下的main_template_vars.php文件。(通常默认情况为includes/templates/template_default/common/main_template_vars.php文件,可能的目录如同上2),默认情况下,将按序尝试调用includes/pages/[main_page]/main_template_vars.php', 若存在则包含该文件,若不存在将分级调用以下文件
(a)includes/templates/[main_page]/.. tpl_[main_page]_defaule.php
(b) includes/templates/template_default/[main_page]/.. tpl_[main_page]_defaule.php
(c) includes/templates/templates/.. tpl_[main_page]_defaule.php
(d) includes/templates/template_default/templates/.. tpl_[main_page]_defaule.php(默认)
(4) 加载js文件(实际上,这些js文件被保存到数组$zv_onload[ ]中),分两步进行:
(a) 包含includes/modules/pages/[main_page]/..目录下所有on_load_*.js形式的文件。(该js文件为<body οnlοad="xxx.js">)
(b) 分级加载on_load_*.js, 依次为
includes/templates/[jscript/on_load]/.. on_load_*.js
includes/templates/template_default/[jscript/on_load]/.. on_load_*.js
includes/templates/ jscript/on_load_ /.. on_load_*.js
includes/templates/template_default/ jscript/on_load_ /.. on_load_*.js
(5) 包含includes/templates/..目录下的tpl_main_page.php文件(该文件为请求页面的主模版文件)。(通常为includes/templates/template_default/common/tpl_main_page.php文件,方法同2)
最后,调用application_bottom.php文件进行收尾清理工作。