本文实例讲述了smarty中post用法。分享给大家供大家参考。具体分析如下:
知道了smarty的运行原理之后,就想写个post的实现过程,以下是实现post的代码,跟独自写php代码差不多,只是多了显示文件
配置文件:conf.php
<?php <br />@header("Content-type: text/html; charset=UTF-8"); <br />require '../libs/Smarty.class.php'; <br />$my=new Smarty; <br />$my->template_dir ='templates/'; <br />$my->compile_dir ='templates_c/'; <br />$my->config_dir ='co<div>)本文来源gaodai.ma#com搞#代!码网_</div><strong>搞代gaodaima码</strong>nfigs/'; <br />$my->cache_dir ='cache/'; <br />?>
index.php
<?php <br />include 'conf.php'; <br />$my->assign('content','welcome to arrival'); <br />$my->assign('mylife',array("生活","吃饭","梦想","凉风","报仇","fuck someone","fuck you die")); <br />$my->display('kk.html'); <br />?>
template下的kk.html【index.php的显示文件】
<br /> <br /> <br /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <br /><title>无标题文档</title> <br /> <br /><body> <br />{$content} <br />{section name=truelife loop=$mylife} <br />{$mylife[truelife]} <br />{/section} <br /> <p>{html_select_time use_24_hours=true}
submit.php
<?php <br /> include 'conf.php'; <br /> $kk=$_POST['conteng']; <br /> $ct=$_POST['ct']; <br /> $sm=new Smarty(); <br /> $sm->assign('content',$kk); <br /> $k=explode("\r\n",$ct); //将字符分隔为数组 <br /> $sm->assign('ml',$k); <br /> $sm->display('m.tpl'); <br />?>
template下的m.tpl文件【submit.php的显示文件】
{$content} <br />{section name=kk loop=$ml} <br />{$ml[kk]}<br /> <br />{/section}
希望本文所述对大家的smarty程序设计有所帮助。