网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > ZenCart
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

Reply
 
Thread Tools Display Modes
  #1   IP: 49.87.2.24
Old 2016-05-14, 09:25 PM
Jaida Jaida is offline
初级会员
 
Join Date: 2013-04-16
Posts: 1
Jaida 现在声名狼藉
Default Zen Cart主要文件的功能总结和提炼

Zen Cart的源码文件中第一句话往往是包含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()是按顺序找的,所以你只要在你的模板文件中存在该文件即可。
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 11:07 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.