增加緩存:./cache/*.html
減少了訪問數據庫的次數
Display(“”,””)
$_GET[“”]
$_SERVER[“REQUST_URI”]
局部緩存
實時性要求比較高
例如:登陸用戶名稱
歡迎Amdin登陸到****
例如:時間日期
解決步驟: 自定義函數(自定義插件)
第一種:插件形式
1) 指定該函數名稱nocache
2) 新建文件./plugins/block.nocache.php
內容:
<?php
function smarty_block_nocache($args, $content){
return $content;}
?>
3)*.php
….
$tpl->assign(“date,date(“H:i:s”));
….
*.tpl
<{nocache}><{$date}><{/nocache}>
所有插件默認被緩存
Smarty. 712 行
Else{
if($tag_command==nocache){
$this->_plugins['block'][$tag_command] = array($plugin_func, null, null, null, false);}
Else{
$this->_plugins['block'][$tag_command] = array($plugin_func, null, null, null, true);
}
}
第二種:php文件內自定義函數並註冊
*.php
$tpl->register_block(“nocache”,”fun1”,false);
function fun1($args,$content){return $content;}
$tpl->assign(“date”,date(“H:i:s”));
*.tpl
<{nocache}><{$date}><{/nocache}>
第三種:smarty內建函數insert
定義一個inser標籤要使用的處理函數
函數名格式爲:
insert_xx(array $params, object &$smarty)
其中的xx是insert的name,也就是說,如果你定義的函數爲insert_abc,則模板中使用方法爲{insert name=abc}參數通過
$params傳入
也可以做成insert插件,文件名命名爲:insert.xx.php,函數命名爲:smarty_insert_aa($params,&$smarty),xx定義同上