WampServer2.1e-x32
1.下载并解压Smarty.我下载的是Smarty-2.6.26.zip,解压后的目录为:E:/myspace/PHP/Smarty-2.6.26
2.在php.ini中配置如下:
; Windows: "/path1;/path2"
;include_path = ".;c:/php/includes"
include_path = ".;E:/myspace/PHP/Smarty-2.6.26/libs"
3.创建模板目录如下:
根目录: E:/myspace/PHP/Smarty_Dirs
模板目录:E:/myspace/PHP/Smarty_Dirs/templates
E:/myspace/PHP/Smarty_Dirs/templates_c
配置目录:E:/myspace/PHP/Smarty_Dirs/configs
缓存目录:E:/myspace/PHP/Smarty_Dirs/cache
4.在模板目录E:/myspace/PHP/Smarty_Dirs/templates中创建模板index.tpl:
<html>
<head><title>{$title}{*这个是注释*}</title></head>
<body>
{$body|count_words}
{$body|capitalize}
</body>
</html>
5.在apache服务器应用目录(E:/myspace/PHP/php_root)中创建Smarty测试目录SmartyTest(E:/myspace/PHP/php_root/SmartyTest).创建测试文件index.php:
<?php
require("Smarty.class.php");
$smarty=new Smarty;
$smarty->template_dir='E:/myspace/PHP/Smarty_Dirs/templates';
$smarty->config_dir='E:/myspace/PHP/Smarty_Dirs/configs';
$smarty->cache_dir='E:/myspace/PHP/Smarty_Dirs/cache';
$smarty->compile_dir='E:/myspace/PHP/Smarty_Dirs/templates_c';
$smarty->assign("title","Smarty Test");
$smarty->assign("body","Hello,This is my first smarty test!");
/*$smarty->assign("title","Smarty测试");
$smarty->assign("body","Hello,这是我的第一个Smarty测试!");*/
$smarty->display("index.tpl");
?>
6.启动服务器(注意前面配置后应重启)测试:http://localhost/SmartyTest/index.php