smarty中post用法实例
实例 用法 post smarty
2023-06-13 09:15:31 时间
本文实例讲述了smarty中post用法。分享给大家供大家参考。具体分析如下:
知道了smarty的运行原理之后,就想写个post的实现过程,以下是实现post的代码,跟独自写php代码差不多,只是多了显示文件
配置文件:conf.php
@header("Content-type:text/html;charset=UTF-8");
require"../libs/Smarty.class.php";
$my=newSmarty;
$my->template_dir="templates/";
$my->compile_dir="templates_c/";
$my->config_dir="configs/";
$my->cache_dir="cache/";
?>
index.php
include"conf.php";
$my->assign("content","welcometoarrival");
$my->assign("mylife",array("生活","吃饭","梦想","凉风","报仇","fucksomeone","fuckyoudie"));
$my->display("kk.html");
?>
template下的kk.html【index.php的显示文件】
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<title>无标题文档</title>
</head>
<body>
{$content}
{sectionname=truelifeloop=$mylife}
{$mylife[truelife]}
{/section}
<p>{html_select_timeuse_24_hours=true}</p>
<formid="form1"name="form1"method="post"action="submit.php">
<p>
<labelfor="conteng"></label>
<inputtype="text"name="conteng"id="conteng"/>
</p>
<p>
<labelfor="ct"></label>
<textareaname="ct"id="ct"cols="45"rows="5"></textarea>
</p>
<inputtype="submit"name="submit"id="submit"value="提交"/>
</form>
<p> </p>
</body>
</html>
submit.php
include"conf.php";
$kk=$_POST["conteng"];
$ct=$_POST["ct"];
$sm=newSmarty();
$sm->assign("content",$kk);
$k=explode("\r\n",$ct); //将字符分隔为数组
$sm->assign("ml",$k);
$sm->display("m.tpl");
?>
template下的m.tpl文件【submit.php的显示文件】
{sectionname=kkloop=$ml}
{$ml[kk]}<br/>
{/section}
希望本文所述对大家的smarty程序设计有所帮助。
相关文章
- ASP.NET Core 6框架揭秘实例演示[35]:利用Session保留语境
- Python os.path模块常见函数用法(实例+详细注释)
- Linux 命令实例精选:掌握技能的利器 (linux命令实例大全)
- Linux ln命令:示例与用法(linuxln命令实例)
- 从mssql连接不同实例的技巧分享(mssql 连接不同实例)
- 号Oracle数据库实例的DG端口号使用说明(oracle dg端口)
- jQuery过滤not()与filter()实例代码
- C++中DeviceIoCteatol的用法实例
- DevExpress之ChartControl创建Drill-Down样式的Title实例
- PHP中ini_set与ini_get用法实例
- CI框架验证码CAPTCHA辅助函数用法实例
- php的dl函数用法实例
- php中chdir()函数用法实例
- PHP中array_slice函数用法实例详解
- Delphi实现碰撞球体完整实例代码
- golang语言中for循环语句用法实例
- C#列表框、复选列表框、组合框的用法实例
- C#语音识别用法实例
- Jackson的用法实例分析
- jQuery使用之处理页面元素用法实例
- smarty内置函数{loteral}、{ldelim}和{rdelim}用法实例
- smarty模板引擎中变量及变量修饰器用法实例
- jquery操作HTML5的data-*的用法实例分享
- DevExpress之SplashScreen用法实例