天天看點

Smarty 學習随記(5)

常量

SMARTY_DIR

是到smarty類目錄的完全路徑,必須以/結束。如果沒有定義,将會自動決定路徑.

SMARTY_CORE_DIR

是到smarty類core檔案目錄的完全路徑,必須以/結束。如果沒有定義,将會自動定義為smarty_dir路徑下面的子目錄.

變量

$template_dir

預設的模闆目錄名,預設為"./templates".

$compile_dir

預設的編譯模闆目錄名,預設為"./templates_c"

$config_dir

預設的config檔案目錄名,預設為"./configs".

$plugins_dir

預設的插件目錄名,預設為"plugins".

$debugging

debugging控制台。即一個顯示變量的視窗.

$debug_tpl

debug視窗的模闆

$debugging_ctrl

另一種控制debugging的方法。

$autoload_filters

對所有的模闆使用過濾程式,這個變量是一個數組,其中關鍵字是過濾的類型,值是過濾的名字。

$compile_check

每次php執行将是否檢視模闆的内容是否改變。

$caching

決定是否緩存檔案執行生成的檔案。

$cache_dir

預設的模闆緩存目錄名,預設為"./cache".

$cache_lifetime

緩存的模闆的過期時間,以秒計算. $caching值為-1則緩存的模闆永不過期.

最後我放個我用的例子.大家僅做一個參考吧!!! <?php

error_reporting(7);

$TurnDot  =  substr(PHP_OS, 0, 3) == 'WIN'  ?  ";"  :  ":"  ;

$doc_root=$_SERVER['DOCUMENT_ROOT'];   //預設擷取根路徑

//$doc_root="E:/Myweb/an-cool.com/Web" ; //這裡是指定路徑

$lib_root=".".$TurnDot.$doc_root."/shopadmin".$TurnDot.$doc_root."/shopadmin/inc".$TurnDot.$doc_root."/".$TurnDot.$doc_root."/jpgraph/src/".$TurnDot.$doc_root."/Smarty/libs/".$TurnDot.$doc_root."/Smarty";

ini_set("include_path",$lib_root);

include("conf.global.php");  //這裡是裝載一個全局配置檔案.

$Templates_root = $doc_root."/templates";  //定義摸版根目錄

define("Templates",$Templates_root);

$templates  = isset($INFO['templates'])  ?  $INFO['templates']  :  'default'  ;

include_once('Smarty.class.php');

$tpl = new Smarty();                                                                   //建立smarty執行個體對象$tpl

$tpl->debugging = false;

$tpl->template_dir   = Templates."/".$templates  ;                             //設定模闆目錄

$tpl->compile_dir    = Templates."/".$templates  ."/templates_c";     //設定編譯目錄

$tpl->cache_dir      = $doc_root."/cache";                                //設定緩存目錄

$tpl->cache_lifetime = 60 * 60 * 24;                                         //設定緩存時間

$tpl->cache_lifetime = 0;                                                          //設定緩存時間

$tpl->caching        = false;                                                        //這裡是調試時設為false,釋出時請使用true

$tpl->left_delimiter = '<{';

$tpl->right_delimiter= '}>';

$tpl->assign("template_dir",  $INFO['site_url']."/templates/".$templates ); //摸闆路徑

$tpl->assign("Site_Url",      $INFO['site_url']); //主站URL

$tpl->assign("LanguageIs",    $INFO['IS']); //語言包類型

$tpl->assign("HtmlTitle", $INFO['site_title']);     //TITLE内容

$tpl->assign("HtmlMeta",  $INFO['meta_keyword']);  //META内容

?>