《PHP學習:Smarty模板簡單配置與使用方法示例》要點:
本文介紹了PHP學習:Smarty模板簡單配置與使用方法示例,希望對您有用。如果有疑問,可以聯系我們。
PHP實戰本文實例講述了Smarty模板簡單配置與使用辦法.分享給大家供大家參考,具體如下:
PHP實戰在Smarty目錄中建立templates,templates_c,configs,cache目錄.以便Smarty進行編譯和緩存.
PHP實戰建立smarty_inc.php文件對smarty進行配置如下:
PHP實戰
<?php
include_once("./smarty/Smarty.class.php"); //包含smarty類文件
$smarty = new Smarty(); //建立smarty實例對象$smarty
$smarty->caching=false; //開發是不建議開啟緩存
$smarty->template_dir="./templates"; //設置模板目錄
$smarty->compile_dir="./templates_c"; //設置編譯目錄
$smarty->cache_dir="./cache"; //緩存文件夾
$smarty->cache_lifetime=60;
$smarty->left_delimiter = "<{"; //左定界符
$smarty->right_delimiter = "}>"; //右定界符
?>
PHP實戰行測試,在根目錄下建立index.php文件:
PHP實戰
<?php
include("smarty_inc.php");
$val= array("丁慶","董丹鳳","情侶");
$smarty->assign("name",$val);
$smarty->display("index.html");
?>
PHP實戰在templates下建立index.html模板:
PHP實戰
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset="utf-8">
<title>測試頁面</title>
</head>
<body>
<{foreach from=$name item=x}>
數組內容:<{$x}> <br/>
<{/foreach}>
</body>
</html>
PHP實戰好了,大功告成,就是這么簡單.
PHP實戰更多關于Smarty相關內容可查看本站專題:《smarty模板入門基礎教程》、《PHP模板技術總結》、《PHP基于pdo操作數據庫技巧總結》、《PHP運算與運算符用法總結》、《PHP網絡編程技巧總結》、《PHP基本語法入門教程》、《php面向對象程序設計入門教程》、《php字符串(string)用法總結》、《php+mysql數據庫操作入門教程》及《php常見數據庫操作技巧匯總》
PHP實戰希望本文所述對大家基于smarty模板的PHP程序設計有所贊助.
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/6527.html