一. 安装
下载最新版本的Smarty。解压下载的文件(目录结构还蛮复杂的)。接下来演示给大家一个安装实例,看过应该会举一反三的。
(1) 在根目录(你的网站目录)下建立了新的目录learn/,再在learn/里建立一个目录smarty/。将刚才解压缩出来的目录的libs/拷贝到smarty/里,再在smarty/里新建templates目录,templates里新建cache/,templates/,templates_c/, config/.
注意:templates_c/的权限为777
(2) 新建一个模板文件:index.tpl,将此文件放在learn/smarty/templates/templates目录下,代码如下:
新建index.php,将此文件放在learn/下:
//注意,若是报有”Parse error: syntax error, unexpected T_STRING in D:\ProgramFiles\AppServ\www\learn\index.php on line 2”的错误,检查每一行的开头是否有空格,删掉后重新执行index.php。
(3) 执行index.php就能看到Hello World!了。
如果必须得使用绝对路径,则是因为服务器不会知道文件在第几层目录中被调用。