Smarty Simple Application example, Smarty application Example
This paper describes a simple application example of Smarty. Share to everyone for your reference, as follows:
<?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"); Open MySQL server connection mysql_select_db ("lava_guess"); Link Database mysql_query ("Set names UTF8"); Solve Chinese garbled problem $sql_list= "select * from t_sys_msg Order by id desc limit 0,10"; $result _list=mysql_query ($sql _list); Executes the SQL statement, returns the result//converts the recordset to an array while ($rs _list=mysql_fetch_array ($result _list)) {$msg _array[]= $rs _list;} $array [] = Array ("NewsID" =>1, "newstitle" = "1th News"); $array [] = Array ("NewsID" =>2, "newstitle" = "2nd News"); $array [] = Array ("NewsID" =>3, "newstitle" = "3rd News"); $array [] = Array ("NewsID" =>4, "newstitle" = "4th News"); $arrAy[] = Array ("NewsID" =>5, "newstitle" = "5th News"); $array [] = Array ("NewsID" =>6, "newstitle" = "6th News"), $smarty->assign ("Newsarray", $array); $smarty Assign ("Hello", $hello);//Assignment $smarty->assign ("Msglist", $msg _array); $smarty->display (' Index.tpl ');? >
Template file: 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} News Number: {$newsArray [Loop].newsid}
News title: {$newsArray [Loop].newstitle}
{Sectionelse} Sorry, there is no news input! {/section}
It is hoped that this article will be helpful to everyone based on smarty template PHP program design.
http://www.bkjia.com/PHPjc/1067841.html www.bkjia.com true http://www.bkjia.com/PHPjc/1067841.html techarticle Smarty Simple Application example, Smarty Application Example This paper describes Smarty simple application example. Share to everyone for your reference, specifically as follows: Phprequire ' smarty/libs/smarty.class.php ';