国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

smarty post實(shí)例

2024-05-04 23:06:42
字體:
供稿:網(wǎng)友

知道了smarty的運(yùn)行原理之后,就想寫個post的實(shí)現(xiàn)過程,以下是實(shí)現(xiàn)post的代碼,跟獨(dú)自寫php代碼差不多,只是多了顯示文件

配置:conf.php

  1. <?php  
  2. @header("Content-type: text/html; charset=UTF-8");  
  3. require '../libs/Smarty.class.php';  
  4. $my=new Smarty;  
  5. $my->template_dir ='templates/';  
  6. $my->compile_dir ='templates_c/';  
  7. $my->config_dir ='configs/';  
  8. $my->cache_dir ='cache/';  
  9. ?> 

index.php

  1. <?php  
  2. include 'conf.php';  
  3. $my->assign('content','welcome to arrival');  
  4. $my->assign('mylife',array("生活","吃飯","夢想","涼風(fēng)","報(bào)仇","fuck someone","fuck you die"));  
  5. $my->display('kk.html');  
  6. ?> 

template下的kk.html【index.php的顯示文件】

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5. <title>無標(biāo)題文檔</title>  
  6. </head>  
  7. <body>  
  8. {$content}  
  9. {section name=truelife loop=$mylife}  
  10. {$mylife[truelife]}  
  11. {/section}  
  12.   <p>{html_select_time use_24_hours=true} </p>  
  13.   <form id="form1" name="form1" method="post" action="submit.php">  
  14.   <p>  
  15.     <label for="conteng"></label>  
  16.     <input type="text" name="conteng" id="conteng" />  
  17.   </p>  
  18.   <p>  
  19.     <label for="ct"></label>  
  20.     <textarea name="ct" id="ct" cols="45" rows="5"></textarea>  
  21.   </p>  
  22.     <input type="submit" name="submit" id="submit" value="提交" />  
  23. </form>  
  24.   <p>&nbsp;</p>  
  25. </body>  
  26. </html> 

submit.php

  1. <?php  
  2.  include 'conf.php';  
  3.  $kk=$_POST['conteng'];  
  4.  $ct=$_POST['ct'];  
  5.  $sm=new Smarty();  
  6.  $sm->assign('content',$kk);   
  7.  $k=explode("/r/n",$ct);  //將字符分隔為數(shù)組  
  8.  $sm->assign('ml',$k);  
  9.  $sm->display('m.tpl');  
  10.  ?> 

template下的m.tpl文件【submit.php的顯示文件】

  1. {$content}  
  2. {section name=kk loop=$ml}  
  3. {$ml[kk]}<br />  
  4. {/section} 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 寻乌县| 高尔夫| 宣威市| 秭归县| 常德市| 滁州市| 观塘区| 临江市| 锦州市| 淮南市| 上犹县| 鸡西市| 江华| 额济纳旗| 阆中市| 宁陵县| 东乌珠穆沁旗| 黄冈市| 新干县| 泸水县| 西藏| 汝城县| 屏山县| 广汉市| 澄城县| 历史| 房山区| 大埔区| 酉阳| 左贡县| 册亨县| 西华县| 镇原县| 桃江县| 策勒县| 双城市| 临朐县| 剑阁县| 淮滨县| 宽城| 商南县|