欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Smarty環(huán)境配置與使用入門(mén)教程

 更新時(shí)間:2016年05月11日 09:27:53   作者:dingyan954  
這篇文章主要介紹了Smarty環(huán)境配置與使用方法,較為詳細(xì)的分析了Smarty環(huán)境的搭建與配置參數(shù)的功能含義,非常簡(jiǎn)單易懂,需要的朋友可以參考下

本文實(shí)例講述了Smarty環(huán)境配置與使用方法。分享給大家供大家參考,具體如下:

下載Smarty(這里以Smarty-2.6.26為例)。解壓下載的文件(目錄結(jié)構(gòu)還蠻復(fù)雜的)。接下來(lái)演示給大家一個(gè)安裝實(shí)例,看過(guò)應(yīng)該會(huì)舉一反三的。

(1) 在根目錄下建立了新的目錄learn/,再在learn/里建立一個(gè)目錄smarty/。將剛才解壓縮出來(lái)的目錄的libs/拷貝到smarty/里,再在smarty/里新建templates目錄,templates里新建cache/,templates/,templates_c/, config/。

(2) 新建一個(gè)模板文件:index.tpl,將此文件放在learn/smarty/templates/templates目錄下,代碼如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.01
<html>
<head>
<metahttp-equiv="Content-Type" content="text/html;charset=gb2312">
<title>Smarty</title></head>
<body>{#$hello#}</body>
</html>

新建index.php,將此文件放在learn/下:

<?php
require 'smarty/libs/Smarty.class.php';
$smarty = new Smarty;//設(shè)置各個(gè)目錄的路徑,這里是安裝的重點(diǎn)
$smarty->template_dir ="smarty/templates/templates";
$smarty->compile_dir ="smarty/templates/templates_c";
$smarty->config_dir = "smarty/templates/config";
$smarty->cache_dir ="smarty/templates/cache";
//smarty模板有高速緩存的功能,如果這里是true的話即打開(kāi)caching,但是會(huì)造成網(wǎng)頁(yè)不立即更新的問(wèn)題,當(dāng)然也可以通過(guò)其他的辦法解決
$smarty->caching = false;
$smarty->left_delimiter = "{#"; //重新定義邊界,因?yàn)槟J(rèn)邊界“{}“符,在html頁(yè)面中嵌入js腳本文件編寫(xiě)代碼段時(shí)使用的就是”{}“符,自定義邊界符還可以是<{ }>, {/ /} 等
$smarty->right_delimiter = "#}";
$hello = "Hello World!";//賦值
$smarty->assign("hello",$hello);//引用模板文件
$smarty->display('index.tpl');?>

(3) 執(zhí)行index.php就能看到Hello World!了。

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《smarty模板入門(mén)基礎(chǔ)教程》、《PHP模板技術(shù)總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基于pdo操作數(shù)據(jù)庫(kù)技巧總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語(yǔ)法入門(mén)教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家基于smarty模板的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論