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}
分享到:
相关推荐
smarty smarty3.6 带例子 下载,好多例子啊
linux+php+smarty模板的例子.zip PHP Web Development在Linux环境中配置(Smarty)
整合了springmvc4 smarty4j的小例子
smarty简易教程,入门级,整个教程分四大部分: 一、模板设计部分 二、程序设计部分 三、实例篇(使用PHP内置MySQL函数) 四、实例篇(使用phplib的DB类)
smarty 的安装例子. hello world...
Smarty Smarty Smarty
smarty两种局部缓存方法和自定义生成静态文件的例子,smarty版本是2.6.26
php+smarty简单新闻管理,便于快速理解smarty结构,方便ASP程序员快速转学PHP.
$smarty= Smarty::instance(); 模板 之前的smarty模板,相当于重新定义了一套标签语言,那么smarty3提供了一种新的模板形式,直接支持php语法的模板。 但是问题就出来了,我们还有必要用模板吗? 引用php类型模板...
这里是关于一个Smarty Demo的例子。
smarty安装及初级使用 在PHP的世界里已经出现了各式各样的模板类,但就功能和速度来说Smarty还是一直处于领先地位,因为Smarty的功能相对强大,所以使用起来比其他一些模板类稍显复杂了一点。现在就用30分钟让您...
smarty3.0,smarty最新版本
Smarty 模板引擎教程,内容主要有基本语法、变量、组合修改器、内建函数、自定义函数、配置文件、控制台调试、缓存、插件扩展、使用技巧和经验等,比较详细的一个中文手册
Smarty最新版官网,Smarty最新版下载自Smarty官网
简单的Smarty应用,使用多样式分页,还带简单管理后台哦。帐号密码都是admin
php模版 (smarty)php模版 (smarty)php模版 (smarty)php模版 (smarty)php模版 (smarty)php模版 (smarty)php模版 (smarty)
这是一个完全用smarty模板开发的留言板程序,供初学者研究和学习,很有用哦
常见的smarty函数使用、smarty简单使用
php5会使用的smarty运算符,smarty是在php前期使用中常见的模版分离,同时国内鼎鼎大名的ecshop也是采用这样方式开发系统
smarty生成的新闻列表静态文件 亲身测试