首页
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
posts - 27, comments - 89, trackbacks - 2
<
2008年7月
>
日
一
二
三
四
五
六
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
与我联系
发短消息
搜索
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
给我留言
查看留言
我参与的团队
HiccDS俱乐部(0/821)
我的标签
java
(4)
php
(2)
mysql
(2)
分页
(1)
远程桌面登陆工具
(1)
文件
(1)
操作
(1)
System.getProterty()
(1)
使用
(1)
Filter
(1)
更多
随笔档案
2008年4月 (2)
2008年2月 (6)
2008年1月 (4)
2007年12月 (9)
2007年10月 (1)
2007年9月 (5)
文章分类
ASP(3)
C#编程(6)
Html(5)
java(12)
Linux(1)
mac(2)
php(6)
ruby on rails(2)
SQL(3)
相册
生活照
积分与排名
积分 - 14797
排名 - 2506
最新评论
1. re: mac下安装ac97的声卡驱动
改/System/Library/Extensions/AppleAC97Audio.kext/Contents/PlugIns/AppleAC97AudioIntelICH.kext/Content...
--张玉峰
2. re: Zend Studio for Eclipse 6.0官方下载地址+注册机(转)
xiexie
--ciweishiwoi
3. re: php中连接mysql(分页显示)
太强了!!!!!顶!!!!!!!!!
--不是神
4. re: Zend Studio for Eclipse 6.0官方下载地址+注册机(转)
多谢.多谢!
--4log
5. re: 无法启动Apache Tomcat服务解决
这样也行,呵呵
--*月明*
阅读排行榜
1. Javascript函数大全(679)
2. Linux Yum命令(转)(604)
3. Hibernate中DetachedCriteria的使用(转)(440)
4. linux下mysql远程登陆(382)
5. struts标签库(339)
评论排行榜
1. MyEclipse注册码收集(4)
2. 在Linux下安装和使用MySQL(4)
3. 使用FLVPlayback组件播放fms(fcs)的流式FLV文件(4)
4. 在Flash中调用xml文档(3)
5. struts标签库(3)
PHP之Smarty简单实现
首先,加载 Smarty 模版引擎,建立 Smarty 对象,设定 Smarty 对象的参数。
//
调用 Smarty
$template_name
=
'
test
'
;
//
模版文件夹名
require_once
( ROOT_PATH
.
'
includes/smarty/Smarty.class.php
'
);
//
包含smarty类文件
$smarty
=
new
Smarty;
//
初始化Smarty
$smarty
->
compile_check
=
true
;
//
打开模版编译检查
$smarty
->
debugging
=
false
;
//
关闭调试
$smarty
->
caching
=
false
;
//
关闭缓存
$smarty
->
template_dir
=
"
template/{
$template_name
}/
"
;
//
设置模版路径
$smarty
->
compile_dir
=
'
template_c
'
;
//
设置编译文件存放的文件夹
$smarty
->
left_delimiter
=
'
[##
'
;
//
设置左边界符
$smarty
->
right_delimiter
=
'
##]
'
;
//
设置右边界符号
然后,调用函数:
require_once
( ROOT_PATH
.
'
mods/mod_main.php
'
);
$func
=
'
main_page
'
;
$main_body
=
$func
();
//
调用函数,实现不同功能,并用$main_body接收返回结果(其实就是一堆HTML)
main_page函数如下:
function
main_page()
//
默认调用的函数
{
global
$smarty
;
require_once
( ROOT_PATH
.
'
includes/ubb.inc.php
'
);
//
包含UBB文件
$message_array
=
array
();
for
(
$i
=
0
;
$i
<
10
;
$i
++
)
//
循环取出结果
{
//
把结果存成二维数组
$message_array
[]
=
array
(
'
id
'
=>
$i
,
'
username
'
=>
'
测试username
'
,
'
content
'
=>
ubb(
'
测试content
'
)
,
//
用ubb函数过滤变量
);
}
$smarty
->
assign(
'
message
'
,
$message_array
);
//
替换模板变量
return
$smarty
->
fetch(
'
message.tpl
'
);
}
利用 Smarty 的 display 方法将网页秀出:
$smarty
->
assign(
'
main_body
'
,
$func
());
//
smarty方法,用来把模板里的[##$main_body##]部分用变量$main_body替换。
$smarty
->
display(
'
test.tpl
'
);
//
输出模板
源代码:
Smarty简单示例
Smarty中文文档:
Smarty中文文档
posted on 2008-07-04 11:55
碎梦
阅读(134)
评论(1)
编辑
收藏
所属分类:
php
Feedback
#1楼
2008-07-04 17:59 |
张玉峰
硬,期待下一好帖。
回复
引用
查看
新用户注册
刷新评论列表
标题
姓名
主页
Email
(博主才能看到)
验证码
*
看不清,换一张
[
登录
][
注册
]
内容(请不要发表任何与政治相关的内容)
博客园首页
新闻频道
社区
小组
博问
网摘
闪存
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
该文被作者在 2008-07-04 12:12 编辑过
成果网帮您增加网站收入
相关文章:
深入浅出之正则表达式(一)
Ajax实现无刷新三联动下拉框
实现土豆网的视频播放
[原创]我的WCF之旅(1):创建一个简单的WCF程序
数据库主键设计之思考
利用 Remoting 实现异步队列机制
相关链接:
所属分类的其他文章:
php得到一个时间的当天、当月、当年的起始时间戳
PHP之Smarty简单实现
Zend Studio 实用快捷键一览表
Zend Studio for Eclipse 6.0官方下载地址+注册机(转)
php中连接mysql(分页显示)
PHP连接MYSQL的两种方法
最新IT新闻:
Google 10周年大事记
Google上下二十年
中华英才网面临外资吞并
软件收入百强张榜 华为中兴海尔列前三
马云vs孙正义:两个“疯子”的对话