smarty簡單應用執行個體,smarty應用執行個體_PHP教程

來源:互聯網
上載者:User

smarty簡單應用執行個體,smarty應用執行個體


本文講述了smarty簡單應用執行個體。分享給大家供大家參考,具體如下:

<?phprequire '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伺服器串連mysql_select_db("lava_guess"); //連結資料庫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); //執行sql語句,返回結果//把記錄集轉換為數組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');?>

模板檔案:index.tpl

Smarty{$hello} {section name=loop loop=$msglist} id: {$msglist[loop].id}--{$msglist[loop].title}----{$msglist[loop].receiver}
{/section}{section name=loop loop=$newsArray}新聞編號:{$newsArray[loop].newsID}
新聞標題:{$newsArray[loop].newsTitle}
{sectionelse}對不起,沒有任何新聞輸入!{/section}

希望本文所述對大家基於smarty模板的php程式設計有所協助。

http://www.bkjia.com/PHPjc/1067841.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1067841.htmlTechArticlesmarty簡單應用執行個體,smarty應用執行個體 本文講述了smarty簡單應用執行個體。分享給大家供大家參考,具體如下: phprequire 'smarty/libs/Smarty.class.php';$...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.