网站地图    收藏   

主页 > 后端 > smarty >

smarty post实例

来源:未知    时间:2014-12-11 18:16 作者:xxadmin 阅读:

[导读] 知道了smarty的运行原理之后,就想写个post的实现过程,以下是实现post的代码,跟独自写php代码差不多,只是多了显示文件 配置:conf.php ?php @header( Content-type:text/html;charset=UTF-8 ); requir...

知道了smarty的运行原理之后,就想写个post的实现过程,以下是实现post的代码,跟独自写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("生活","吃饭","梦想","凉风","报仇","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>无标题文档</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);  //将字符分隔为数组  
  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} 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论