smarty简单应用实例
框架(架构)  /  管理员 发布于 6年前   97
本文讲述了smarty简单应用实例。分享给大家供大家参考,具体如下: 模板文件:index.tpl 希望本文所述对大家基于smarty模板的php程序设计有所帮助。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"); //打开MySQL服务器连接mysql_select_db("lava_guess"); //链接数据库mysql_query("set names utf8"); //解决中文乱码问题$sql_list="Select * from t_sys_msg Order by id desc limit 0,10";$result_list=mysql_query($sql_list); //执行sql语句,返回结果//把记录集转换为数组while($rs_list=mysql_fetch_array($result_list)) { $msg_array[]=$rs_list;}$array[] = array("newsID"=>1, "newsTitle"=>"第1条新闻"); $array[] = array("newsID"=>2, "newsTitle"=>"第2条新闻"); $array[] = array("newsID"=>3, "newsTitle"=>"第3条新闻"); $array[] = array("newsID"=>4, "newsTitle"=>"第4条新闻"); $array[] = array("newsID"=>5, "newsTitle"=>"第5条新闻"); $array[] = array("newsID"=>6, "newsTitle"=>"第6条新闻");$smarty->assign("newsArray", $array);$smarty->assign("hello",$hello);//赋值$smarty->assign("msglist",$msg_array);$smarty->display('index.tpl');?>
{$hello}
{section name=loop loop=$msglist} id: {$msglist[loop].id}--{$msglist[loop].title}----{$msglist[loop].receiver}
{/section}
{section name=loop loop=$newsArray}新闻编号:{$newsArray[loop].newsID}
新闻标题:{$newsArray[loop].newsTitle}
{sectionelse}对不起,没有任何新闻输入!{/section}您可能感兴趣的文章:
123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号