找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1619|回复: 0
打印 上一主题 下一主题

smarty简单应用实例

[复制链接]

2617

主题

2617

帖子

7789

积分

论坛元老

Rank: 8Rank: 8

积分
7789
跳转到指定楼层
楼主
发表于 2018-2-14 05:41:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            本文讲述了smarty简单应用实例。分享给大家供大家参考,具体如下:
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');
?>
模板文件:index.tpl
Smarty

{$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}
希望本文所述对大家基于smarty模板的php程序设计有所帮助。
            
            
您可能感兴趣的文章:
  • Smarty模板快速入门
  • Smarty安装配置方法
  • php smarty模版引擎中的缓存应用
  • php smarty模版引擎中的缓存应用
  • FCKeditor smarty 编辑器的应用PHP
  • ThinkPHP使用smarty模板引擎的方法
  • smarty半小时快速上手入门教程
  • PHP文件缓存smarty模板应用实例分析
  • Smarty高级应用之缓存操作技巧分析
  • Smarty模板常见的简单应用分析
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端