这段时间一直学习了一点PHP的知识,想要提升一下自己在技术方面的缺陷, 现在照猫画虎也能写一段PHP代码了, 这篇文章就当做是一个学习笔记把, 不喜欢程序的朋友,可以直接了略过了,^_^。
Ok下面了介绍一下如何在Xampp这个PHP环境中调用Smarty模板引擎。
(我的XAMPP安在D:\xampp下)
先把Smarty的所有文件放到D:\xampp\smarty下,接着修改D:\xampp\apache\bin下的php.ini中的 include_path如下:
; UNIX: “/path1:/path2″
;include_path = “.:/php/includes”
;
; Windows: “\path1;\path2″
include_path = “.;D:\xampp\php\pear\;D:\xampp\smarty\libs”
测试一下:
在htddoc下新建一文件夹test,在test中新建文件夹templates(把模板放在这里)和templates_c(这个文件夹一定不能少,不然会出现这种错误:the $compile_dir ‘templates_c’ does not exist, or is not a directory.)。
在templates 中新建index.tpl:
<html>
<head></head>
<body>
Hello,{$name};
</body>
</html>
在test下新建index.php:
<?php
require(“Smarty.class.php”);
$smarty=new Smarty();
$smarty->assign(“name”,”lihaopeng”);
$smarty->display(“index.tpl”);
?>
启动服务器,访问http://localhost:8888/test,结果是:
Hello,lihaopeng;
成功了