PHP頁面

成都創(chuàng)新互聯(lián)提供
成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、網(wǎng)頁設(shè)計(jì),
品牌網(wǎng)站建設(shè),
廣告投放等致力于企業(yè)網(wǎng)站建設(shè)與公司網(wǎng)站制作,10多年的網(wǎng)站開發(fā)和建站經(jīng)驗(yàn),助力企業(yè)信息化建設(shè),成功案例突破上1000+,是您實(shí)現(xiàn)網(wǎng)站建設(shè)的好選擇.left_delimiter="<{";
$smarty->right_delimiter="}>";
//設(shè)置為false 定界符號左右可以有空格
$smarty->auto_literal = false;
//添加一個插件的目錄
//$smarty->setPluginsDir(ROOT."/libs/myplugins/");
//注意添加一個插件,要把系統(tǒng)默認(rèn)設(shè)置的路徑加入 否則不能使用默認(rèn)系統(tǒng)的插件
$smarty->setPluginsDir(array(
ROOT."/libs/plugins/",//系統(tǒng)默認(rèn)設(shè)置的路徑
ROOT."/libs/myplugins/",//自定義的
));
//連接數(shù)據(jù)庫
try{
$pdo = new PDO(DSN, DBUSER,DBPWD);
}catch(PDOException $e){
echo "數(shù)據(jù)庫連接失敗:".$e->getMessage();
exit;
}
$query = "select id, username, password,email from users limit 3";
$stmt = $pdo->prepare($query);
$stmt ->execute();
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
$smarty->assign('users',$users);
//var_dump($users);
$query = "desc users";
$stmt = $pdo->prepare($query);
$stmt ->execute();
$tdname = $stmt->fetchAll(PDO::FETCH_COLUMN);
//var_dump($tdname);
$page = new Page(20, 2);
$smarty->assign('tdname',$tdname);
$smarty->assign('fpage',$page->fpage());
//變量輸出
$smarty->display('hello.tpl');
//返回輸出緩沖區(qū)的內(nèi)容
$content = ob_get_contents();
//將一個字符串寫入文件
file_put_contents("./cache/newindex{$_GET['page']}.html", $content);
//沖刷出(送出)輸出緩沖區(qū)中的內(nèi)容
ob_flush();
echo "緩存文件不存在,查詢數(shù)據(jù)庫,再生成緩存文件,輸出到瀏覽器";
}else{
include $file;
echo "直接加載緩存文件";
}
?>
模板tpl頁面
<{config_load file="../config/my.conf " section="index"}>
'>
<{#title#}>
用戶信息表
index |
iteration |
<{foreach $tdname as $val}>
<{$val}> |
<{/foreach}>
<{section name="one" loop=$users }>
<{if $smarty.section.one.first}>
<{elseif $smarty.section.one.last}>
<{elseif $smarty.section.one.iteration is even}>
<{else}>
<{/if}>
<{$smarty.section.one.index}> |
<{$smarty.section.one.iteration}> |
<{$users[one].id}> |
<{$users[one].username}> |
<{$users[one].password}> |
<{$users[one].email}> |
<{sectionelse}>
沒有用戶查詢出來!
<{/section}>
<{$fpage}>
|
瀏覽器頁面

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
名稱欄目:PHPSmarty頁面靜態(tài)化加分頁和緩存控制-創(chuàng)新互聯(lián)
本文鏈接:
http://weahome.cn/article/djdojg.html