读书人

window上smarty环境搭建

发布时间: 2012-10-26 10:30:59 作者: rapoo

window下smarty环境搭建

1.在网上下载最新的smarty文件。

2,解压缩Smarty包,如放在c:/java/php/smarty

?3、找到你的php.ini配置文件(可以通过运行phpinfo()查看此文件路径,但一般都放在系统目录下)修改php.ini的include_path选项,把smarty的库文件路径加上,比如:

?? include_path = ".;c:/java/php/smarty"

?? 提醒一下,php.ini中一共有两处include_path,一处是Unix下使用的,一处是windows下使用的,要修改windows下使用的:

-------------------------

?? ; Windows: "\path1;\path2"

?? include_path = ".;c:\php4\includes;d:\smarty\libs"

--------------------------

4、重新启动服务,使更改的配置文件生效。

?

5、在你的项目中建一个MySmarty的目录,再在Mysmarty目录下建一个dir目录,并在dir目录下创建configs(存放配置文件)目录,templates(存放模板)目录,cache(存放缓存)目录,templates_c(存放编译后的文件)等四个目录

6、这时候安装工作基本完成,可以进行第一个简单例子的测试:

?? 在你的网站目录下建立 index.php文件,并且在(网站目录)/MySmarty/dir/templates/下建立index.tpl文件,分别输入以下代码

? index.php

? <?php

?? //载入Smarty库

?? require('Smarty.class.php');

??

$smarty = new Smarty;???

?? //下面的(你的网站目录)用绝对路径,比如d:/intepub/wwwroot

$smarty-??? >template_dir = '(你的网站目录)/MySmarty/templates';

$smarty-??? >config_dir = '(你的网站目录)/MySmarty/config';

$smarty-??? >cache_dir = (你的网站目录)/MySmarty/smarty_cache';

$smarty-??? >compile_dir = (你的网站目录)/MySmarty/smarty_templates_c';

?? //上面四行为使用Smarty前的必要参数配置

$smarty-??? >assign('name','跟17PHP学安装Smarty');

$smarty-??? >display('index.tpl');

?>

? index.tpl

? <html>

? <body>

$name}!?? 你好,{

? </body>

? </html>

7、运行index.php(当然是在你的web服务器上运行,和运行普通php文件完全一样。)

? http://localhost/index.php

? 这时候如果看到下面的输出结果,说明你安装成功了~~~是不是很简单呢?

读书人网 >编程

热点推荐