《PHP實(shí)例:smarty簡(jiǎn)單應(yīng)用實(shí)例》要點(diǎn):
本文介紹了PHP實(shí)例:smarty簡(jiǎn)單應(yīng)用實(shí)例,希望對(duì)您有用。如果有疑問,可以聯(lián)系我們。
PHP編程本文講述了smarty簡(jiǎn)單應(yīng)用實(shí)例.分享給大家供大家參考,具體如下:
PHP編程
<?php
require 'smarty/libs/Smarty.class.php';
$smarty = new Smarty;
$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";
$hello = "Hello World!";
$smarty->compile_check = true;
//$smarty->debugging = true;
$smarty->debugging = false;
$smarty->caching=true;
$conn=mysql_connect("localhost", "root","root"); //打開MySQL服務(wù)器連接
mysql_select_db("lava_guess"); //鏈接數(shù)據(jù)庫
mysql_query("set names utf8"); //辦理中文亂碼問題
$sql_list="Select * from t_sys_msg Order by id desc limit 0,10";
$result_list=mysql_query($sql_list); //執(zhí)行sql語句,返回結(jié)果
//把記錄集轉(zhuǎn)換為數(shù)組
while($rs_list=mysql_fetch_array($result_list))
{
$msg_array[]=$rs_list;
}
$array[] = array("newsID"=>1, "newsTitle"=>"第1條新聞");
$array[] = array("newsID"=>2, "newsTitle"=>"第2條新聞");
$array[] = array("newsID"=>3, "newsTitle"=>"第3條新聞");
$array[] = array("newsID"=>4, "newsTitle"=>"第4條新聞");
$array[] = array("newsID"=>5, "newsTitle"=>"第5條新聞");
$array[] = array("newsID"=>6, "newsTitle"=>"第6條新聞");
$smarty->assign("newsArray", $array);
$smarty->assign("hello",$hello);
//賦值
$smarty->assign("msglist",$msg_array);
$smarty->display('index.tpl');
?>
PHP編程模板文件:index.tpl
PHP編程
<html>
<head>
<metahttp-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Smarty</title></head>
<body>
<hr>
{$hello}
<hr>
{section name=loop loop=$msglist}
id: {$msglist[loop].id}--{$msglist[loop].title}----{$msglist[loop].receiver}<br>
{/section}
<hr>
{section name=loop loop=$newsArray}
新聞編號(hào):{$newsArray[loop].newsID}<br>
新聞標(biāo)題:{$newsArray[loop].newsTitle}<br><hr>
{sectionelse}
對(duì)不起,沒有任何新聞?shì)斎?
{/section}
PHP編程希望本文所述對(duì)大家基于smarty模板的php程序設(shè)計(jì)有所贊助.
《PHP實(shí)例:smarty簡(jiǎn)單應(yīng)用實(shí)例》是否對(duì)您有啟發(fā),歡迎查看更多與《PHP實(shí)例:smarty簡(jiǎn)單應(yīng)用實(shí)例》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請(qǐng)注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/8475.html