zoukankan      html  css  js  c++  java
  • ZenCart目录说明

    ZenCart采用摸板,单一文件index.php入口,后面跟参数,参数决定显示的内容,基本上网页变换的部分只是中间的主区域。

    admin 后台管理目录
    cache 缓存目录
    docs 文档目录
    download 用于存放下载类商品
    editors 所见即所得编辑器
    email 电子邮件模版目录
    extras 测试文件目录
    images 商品图片目录
    includes 前台
    media 媒体类商品目录
    pub 公用目录(空)

    includes里面的目录:
    auto_loaders 自动加载的脚本
    classes 主要的类函数
    extra_cart_actions 空
    extra_configures 第三方模块设置文件
    extra_datafiles 第三方模块数据表名定义
    functions 主要的功能函数
    index_filters 过滤功能
    init_includes 初始化功能
    languages 语言文件包目录
    modules 所有的模块目录
    templates 模版目录

    重点介绍几个文件

    includes目录,该目录无疑是zencart的核心(前台),

    通常情况下index.php第一句话则是包含include目录下的application_top.php文件,如:require(’includes/application_top.php’);

    在该系统中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是怎么根据摸版把内容显示出来的require(’includes/application_top.php’);初始化所以需要用到的公共信息以后接下来就应该是显示了,在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()是按顺序找的,所以你只要在你的模板文件中存在该文件即可

  • 相关阅读:
    Java中Class.forName()用法和newInstance()方法详解
    开发和学习中好用的工具
    ubuntu修改默认的apt源
    区块链共识算法总结(PBFT,Raft,PoW,PoS,DPoS,Ripple)
    比特币白皮书:一个点对点的电子现金系统(百度网盘)
    session和cookie的区别
    HTTP中GET,POST和PUT的区别
    三小时快速入门Python终结篇--其他模块导入
    C/C++ 多继承{虚基类,虚继承,构造顺序,析构顺序}
    C++ 实现vector<std:string> 版本
  • 原文地址:https://www.cnblogs.com/lookyou/p/2118815.html
Copyright © 2011-2022 走看看