现在的位置: 首页 > 综合 > 正文

zen cart主要文件说明

2012年12月19日 ⁄ 综合 ⁄ 共 4071字 ⁄ 字号 评论关闭

zencart的源码文件中第一句话往往是包括include目录下的application_top.php文件,如:require(’includes/application_top.php’);

在zencart零碎中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是怎样按照摸版把内容显示出来的。
在index.php的第29行有句

$directory_array = $template->get_template_part($code_page_directory, ‘/^header_php/’);

由于全部初始化任务已然完成,因此我们就能够在下面的文件找到他们的定义,如
$autoLoadConfig[100][] = array(’autoType’=>’classInstantiate’,'className’=>’template_func’,'objectName’=>’template’);

在这里就定义了$template = new template_func(); ,接着$code_page_directory变量的定义是在init_includes/init_sanitize.php文件中定义在这里必需要对class/template_func.php中定义的template_func类比拟熟习,在该类中重要定义了两个办法get_template_dir()和get_template_part();
这两个办法在zencart的模板运用中起到了确定性的作用。

get_template_dir办法function get_template_dir($template_code, $current_template, $current_page, $template_dir, $debug=false),它定义了5个参数,第一个参数普通是个文件名,它是用来判别后两个参数构成的目录中有没有婚配$template_code的这个文件,该类复写了默许的零碎函数file_exists因此很多初学者能够会比拟疑惑

function get_template_dir($template_code, $current_template, $current_page, $template_dir, $debug=false) {
//echo ‘template_default/’ . $template_dir . ‘=’ . $template_code;

if($this->file_exists($current_template . $current_page, $template_code)){
return $current_template . $current_page . ‘/’;
}elseif ($this->file_exists(DIR_WS_TEMPLATES . ‘template_default/’ . $current_page, ereg_replace(’/', ”, $template_code), $debug)){
return DIR_WS_TEMPLATES . ‘template_default/’ . $current_page;
} elseif ($this->file_exists($current_template . $template_dir, ereg_replace(’/', ”, $template_code), $debug)){
return $current_template . $template_dir;
} else {
return DIR_WS_TEMPLATES . ‘template_default/’ . $template_dir;
//return $current_template . $template_dir;
}
}

/*

includes/templates/zccn/index
includes/templates/template_default/index
includes/templates/zccn/common
includes/templates/template_default/common
*/

get_template_part()办法有两个函数,第一个参数是文件目录,第二个参数是婚配的要求,执行的后果是包括该目录下全部文件名婚配这个要求的文件

比方$directory_array = $template->get_template_part($code_page_directory, ‘/^header_php/’);
这句话执行的后果就是前往目录下$code_page_directory全部文件名以header_php扫尾的文件
如此时的url(http://localhost/zencart/index.php?main_page=product_info&cPath=49_27&products_id=83)
在应该检查init_sanitize.php中$code_page_directory的定义此时的$code_page_directory的值应该是includes/modules/product_info/
因此它就应该包括该目录下全部以header_php扫尾的文件,在这里好象就唯有一个header_php.php

$directory_array = $template->get_template_part($code_page_directory, ‘/^header_php/’);这个包括文件实际上是初始化前台不同页面显示所需求用到的变量函数,重要是初始化数据库的东西,由于每个页面需求的数据材料都有能够不同,因此index.php?main_page=index 当main_page的值不同是在includes/modules/目录下都会有个相应的目录,这里是index目录
只需晓得了这两个办法的用法,你就会晓得模板文件都是怎样显示出来的了
再来说明一 require($template->get_template_dir(’html_header.php’,DIR_WS_TEMPLATE, $current_page_base,’common’). ‘/html_header.php’);

假定目前url:http://localhost/zencart/index.php?main_page=index&cPath=48
DIR_WS_TEMPLATE 定义是在includes/init_templates.php中定义define(’DIR_WS_TEMPLATE’, DIR_WS_TEMPLATES . $template_dir . ‘/’);,由于我如今用的是默许的zccn模板
因此如今的DIR_WS_TEMPLATE=includes/templates/zccn/
$current_page_base在这里已然就是index
面已然说明了$template->get_template_dir()的办法了

程序会顺次在
includes/templates/zccn/index
includes/templates/template_default/index
includes/templates/zccn/common
includes/templates/template_default/common

这四个目录下找html_header.php,在这里,最后在template_default\common目录下找到html_header.php
到这里就能够本身写摸板文件了,由于$template->get_template_dir()是按顺序找的,因此你只需在你的模板文件中存在该文件便可

抱歉!评论已关闭.