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

Smarty模板簡單配置與使用方法示例

 更新時間:2016年05月23日 09:43:36   作者:yanhui_wei  
這篇文章主要介紹了Smarty模板簡單配置與使用方法,涉及Smarty模板的基本配置與緩存文件的相關(guān)使用技巧,需要的朋友可以參考下

本文實(shí)例講述了Smarty模板簡單配置與使用方法。分享給大家供大家參考,具體如下:

在Smarty目錄中建立templates,templates_c,configs,cache目錄。以便Smarty進(jìn)行編譯和緩存。

建立smarty_inc.php文件對smarty進(jìn)行配置如下:

<?php
include_once("./smarty/Smarty.class.php"); //包含smarty類文件
$smarty = new Smarty(); //建立smarty實(shí)例對象$smarty
$smarty->caching=false; //開發(fā)是不建議開啟緩存
$smarty->template_dir="./templates";  //設(shè)置模板目錄
$smarty->compile_dir="./templates_c";  //設(shè)置編譯目錄
$smarty->cache_dir="./cache";  //緩存文件夾
$smarty->cache_lifetime=60;
$smarty->left_delimiter = "<{";  //左定界符
$smarty->right_delimiter = "}>"; //右定界符
?>

行測試,在根目錄下建立index.php文件:

<?php 
include("smarty_inc.php");
$val= array("丁慶","董丹鳳","情侶");
$smarty->assign("name",$val);
$smarty->display("index.html");
?>

在templates下建立index.html模板:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8">
<title>測試頁面</title>
</head>
<body>
<{foreach from=$name item=x}>
數(shù)組內(nèi)容:<{$x}> <br/>
<{/foreach}>
</body>
</html>

好了,大功告成,就是這么簡單。

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

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

相關(guān)文章

最新評論