Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6541377
  • 博文数量: 915
  • 博客积分: 17977
  • 博客等级: 上将
  • 技术积分: 8846
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-26 09:59
个人简介

一个好老好老的老程序员了。

文章分类

全部博文(915)

文章存档

2022年(9)

2021年(13)

2020年(10)

2019年(40)

2018年(88)

2017年(130)

2015年(5)

2014年(12)

2013年(41)

2012年(36)

2011年(272)

2010年(1)

2009年(53)

2008年(65)

2007年(47)

2006年(81)

2005年(12)

分类: Python/Ruby

2011-08-01 12:00:03

Smarty是Php下的模板引擎技术,和apache的java 模板技术velocity原理一样,只是velocity适用于java 语言,而Smarty适用于php语言。
首先从下载smarty,目前最新版本是3.1rc1。我们将其中的libs目录解压到web默认目录。smarty的配置还是很简单的。
首先需要建立四个目录,templates,templates_c,cache和configs。
接着编写一个测试用php,我暂且命名为smartytest.php
  1. <?php
  2. require('libs/smarty.class.php');
  3. $smarty = new Smarty();
  4. $smarty->setTemplateDir('templates');
  5. $smarty->setCompileDir('templates_c');
  6. $smarty->setCacheDir('cache');
  7. $smarty->setConfigDir('configs');
  8. $smarty->assign('name','Ned');
  9. $smarty->display('smartytest.tpl');
  10. ?>
接着编辑需要的模板文件,模板文件需要放在templates下,暂且命名为smartytest.tpl。
  1. <html>
  2.     <head>
  3.     <title>Smarty Test</title>
  4.     </head>
  5.     <body>
  6.     Hello,{$name}!
  7.     </body>
  8. </html>

这样我们浏览smartytest.php。将会看到页面输出Hello,Ned!。

如果PHP安装有问题,可以使用$smarty->testInstall();进行测试。

注意在Linux下,需要将template_c和cache目录的用户和组修改为nobody,并置权限为rwxrwxrx。

Smarty的官方文档参见http://www.smarty.net/documentation,最新版本有日文版文档,但没有中文的。

阅读(2462) | 评论(0) | 转发(0) |
0

上一篇:log4php使用手记

下一篇:ThinkPHP使用手记

给主人留下些什么吧!~~