安装Smarty
下载页面:http://www.smarty.net/download.php,下载Latest Stable Release,我选择的版本是2.6.26
解压到D:\php\smarty\,这个是我的安装路径,可以根据自己的需要更改,但是注意以下有这个路径的都需要修改
配置Smarty
修改PHP安装目录下的php.ini,找到如下两行所在的位置:
1 2 | ; Windows: "\path1;\path2" ;include_path = ".;c:\php\includes" |
修改为:
1 2 | ; Windows: "\path1;\path2" include_path = ".;D:\php\smarty\libs" |
重启Apache或者IIS
在你的网站目录(我网站的路径为D:/php/workspace/happylink,你同样需要根据实际情况修改)下新建两个文件夹
D:/php/workspace/happylink/smarty/templates
D:/php/workspace/happylink/smarty/configs
在smarty的安装目录(即d:/php/smarty)下新建两个文件夹:
d:/php/smarty/templdates_c
d:/php/smarty/cache
在网站目录(即D:/php/workspace/happylink)下创建index.php,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | < ?php // load Smarty library require('Smarty.class.php'); // change the following 2 lines define('WEB_ROOT', 'D:/php/workspace/happylink'); define('SMARTY_ROOT', 'D:/php/smarty'); $smarty = new Smarty; $smarty->template_dir = WEB_ROOT.'/smarty/templates'; $smarty->config_dir = WEB_ROOT.'/smarty/config'; $smarty->cache_dir = SMARTY_ROOT.'/cache'; $smarty->compile_dir = SMARTY_ROOT.'/templates_c'; $smarty->assign('name','fish boy!'); $smarty->display('index.tpl'); ?> |
在D:/php/workspace/happylink/smarty/templates目录下建立index.tpl,代码如下:
1 2 3 4 5 | <html> <body> Hello, {$name}! </body> </html> |
访问http://localhost/happy/index.php,即可以看到显示了“Hello, fish boy!! ”的页面,到目前为止smarty就安装和配置好了。
如果出现如下的警告信息:
Warning: strftime() [function.strftime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for '8.0/no DST' instead in D:\php\smarty\libs\Smarty_Compiler.class.php on line 400
第一种解决办法是修改php.ini,把"date.timezone="取消注释(即把前面的分号去掉)并赋值为PRC,保存后重启Apache或者IIS就行了。 第二种是在index.php的开头添加设置默认时区的代码即可:
1 2 3 | < ?php date_default_timezone_set("PRC"); ?> |
谢谢分享
按照此设置,测试页面显示空白。
已经搞定,文件夹路径中多了个空格,实在让人纠结…
是我的博客里面写错了么?如果是复制粘贴的话是很容易出这样的问题的,呵呵