smarty简单测试例子
2009-05-21 13:52
330 查看
smarty简单测试例子
<?php
require 'smarty/libs/Smarty.class.php';
$smarty = new Smarty;
$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
<html>
<head>
<metahttp-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Smarty</title></head>
<body>
<hr>
{$hello}
<hr>
{section name=loop loop=$msglist}
id: {$msglist[loop].id}--{$msglist[loop].title}----{$msglist[loop].receiver}<br>
{/section}
<hr>
{section name=loop loop=$newsArray}
新闻编号:{$newsArray[loop].newsID}<br>
新闻标题:{$newsArray[loop].newsTitle}<br><hr>
{sectionelse}
对不起,没有任何新闻输入!
{/section}
<?php
require 'smarty/libs/Smarty.class.php';
$smarty = new Smarty;
$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
<html>
<head>
<metahttp-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Smarty</title></head>
<body>
<hr>
{$hello}
<hr>
{section name=loop loop=$msglist}
id: {$msglist[loop].id}--{$msglist[loop].title}----{$msglist[loop].receiver}<br>
{/section}
<hr>
{section name=loop loop=$newsArray}
新闻编号:{$newsArray[loop].newsID}<br>
新闻标题:{$newsArray[loop].newsTitle}<br><hr>
{sectionelse}
对不起,没有任何新闻输入!
{/section}
相关文章推荐
- Python自动化测试例子--一个简单的自动化测试用例脚本--批量执行测试用例
- 一个最简单的SOAP客户端与服务端测试实例(主要是该例子一个类中写了多个方法)
- Android最简单的基于FFmpeg的例子(二)---测试编译好的SO库
- 主设备号和file_operations结构关系; ioctl和unlocked_ioctl, ioctl简单测试例子
- 一个简单的epoll测试例子
- 学习使用Robot Framework自动化测试框架(二)——简单测试例子
- IKAnalyzer结合Lucene使用和单独使用例子 简单性能测试
- 简单例子测试Ubuntu安装的mysql开发包SDK,附编译选项说明
- 5、Cocos2dx 3.0小游戏开发的例子寻找测试三个简单的介绍和总结
- 简单测试运行时类信息(RTTI),附详细例子
- Jedis几个简单测试例子
- 一个简单的GNU getopt函数的测试例子
- java socket本地测试简单例子
- delphi 三层架构简单例子(经测试成功)
- SDL ios音频简单测试例子-借鉴雷大神的代码
- linux下对信号量测试的一个简单例子
- 使用smarty 缓存的简单例子
- boost mpi 简单例子测试
- sparkstreaming性能测试简单例子--53
- 使用jmeter进行接口压力测试的一个简单例子