337p日本大胆噜噜噜噜,国产在线|日韩,亚洲品牌自拍一品区9,精品国产一区三区,国产精品密蕾丝视频下载,国产亚洲三区

歡迎光臨
我們一直在努力

ZenCart深入二次開發(fā)-核心文件說明

想對ZenCart深入了解的程序猿可以認真看看zencart的文件結(jié)構(gòu)…

1.大家可以看到ZenCart根目錄index.php文件中第一句話是包含include目錄下的application_top.php文件,如:require(’includes/application_top.php’);

zencart系統(tǒng)中application_top.php負責的是初始化工作,比如加載配置文件include(’includes/configure.php’);,如果系統(tǒng)沒檢測到該文件的存在則會嘗試調(diào)用安裝文件。

然后它會自動遍歷include/extra_configures下的配置文件并包含進來。

在加載了系統(tǒng)配置文件以后接下來是一個非常重要的文件,這也導致了zencart和oscommerce感覺上很大不同的原因,首先調(diào)用一個文件require(’includes/initsystem.php’);
在initsystem.php中最先加載include/auto_loaders/config.core.php,config.core.php 是一個二圍數(shù)組$autoLoadConfig,即以數(shù)組的形式保存文件的信息供后面文件調(diào)用,然后系統(tǒng)會接著加載完 include/auto_loaders目錄下所有文件名匹配$loaderPrefix(默認為config)的文件。

上面程序執(zhí)行完以后就是加載自動執(zhí)行程序了require(’includes/autoload_func.php’);在這里它會遍 歷$autoLoadConfig數(shù)組,它最終執(zhí)行的效果會包含所有必須用到的函數(shù)或者類的定義,還有變量的初始化,config.core.php里面 的注釋比較清楚比如

$autoLoadConfig[0][] = array(’autoType’=>’class’,’loadFile’=>’class.base.php’);

在autoload_func.php里面執(zhí)行完以后的效果就是require(DIR_WS_CLASSES . ‘class.base.php’),大部分的初始化化工作是通過包含init_includes目錄下的文件來實現(xiàn)的,如:

$autoLoadConfig[110][] = array(’autoType’=>’init_script’,’loadFile’=> ‘init_templates.php’);

它在執(zhí)行完autoload_func.php文件后就已經(jīng)加載了init_includes目錄下的init_templates.php文件。

 

2.下面來介紹下ZenCart是怎么根據(jù)摸版把內(nèi)容顯示出來的。
在index.php的第29行有句

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

由于所有初始化工作已經(jīng)完成,所以我們就可以在上面的文件找到他們的定義,如
$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個參數(shù),第一個參數(shù)一般是個文件名,它是用來判斷后兩個參數(shù)組成的目錄中有沒有匹配$template_code 的這個文件,該類復寫了默認的系統(tǒng)函數(shù)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()方法有兩個函數(shù),第一個參數(shù)是文件目錄,第二個參數(shù)是匹配的條件,執(zhí)行的結(jié)果是包含該目錄下所有文件名匹配這個條件的文件

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

這句話執(zhí)行的結(jié)果就是返回目錄下$code_page_directory所有文件名以header_php開頭的文件

如此時的url(http://localhost/zencart/index.php?main_page=product_info&cPath=49_27&products_id=83)

你現(xiàn)在應該查看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/’);這個包含文件其實是初始化前臺不同頁面顯示所需要用到的變量函數(shù),主要是初始化數(shù)據(jù)庫的東西,因為每個頁面需要的數(shù)據(jù) 資料都有可能不同,所以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 . ‘/’);,因為我現(xiàn)在用的是默認的zccn模板

所以現(xiàn)在的DIR_WS_TEMPLATE=includes/templates/zccn/

$current_page_base在這里已經(jīng)就是index

上面已經(jīng)解釋了$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,最先優(yōu)先當前模板的。

未經(jīng)允許不得轉(zhuǎn)載:外貿(mào)商城系統(tǒng),外貿(mào)網(wǎng)站模板,php建站教程,zencart模板 » ZenCart深入二次開發(fā)-核心文件說明

分享到:更多 ()

35PHP 更全 更專業(yè) 更方便