Windows环境下smarty安装最简明教程

来源:互联网 发布:淘宝和京东用户人群 编辑:程序博客网 时间:2024/05/23 01:12
1、下载Smarty包
可以从官方站点下载:http://smarty.php.net

2、解压缩Smarty包并找到合适的位置存放,文件夹名存为是Smarty。将含有Smarty文件的文件夹拷贝到某一个目录下。

下面内容中,我们都是假设你的文件放在了C:/Apache2/include/Smarty下。

3、找到你的php.ini配置文件修改php.ini的include_path选项,把smarty的库文件路径加上,比如:
include_path = "C:/Apache2/include/Smarty/libs"

提醒一下,php.ini中一共有两处include_path,一处是Unix下使用的,一处是windows下使用的,要修改windows下使用的:
-------------------------------------------------------------
; Windows: "/path1;/path2"
include_path = "C:/Apache2/include/Smarty/libs"

4、在你的网站目录下创建一个文件夹,名字任意,假设叫Smarty:
然后再在这个MySmarty目录下创建4个文件夹,templates、configs、template-c和cache。
创建完成之后如下:
(你的网站目录)/Smarty/templates (这个目录用来存放模版)
(你的网站目录)/Smarty/configs (这个目录用来存放一些配置信息)

(你的网站目录)/Smarty/templates_c (这个目录用来存放编译文件)

(你的网站目录)/Smarty/cache (这个目录用来存放缓存)

5、这时候你别忘了把我们上面从一开始到现在创建的四个文件夹的权限设置好。

,在“属性”中打开“安全”标签,在里面列出了可以访问这个目录的用户列表,

如果没有web访问权限,则需要添加,把Internet来宾帐户和启动IIS进程帐户两个帐户都添加上即可。如果觉得麻烦,可以直接将Everyone用

户组添加上,允许任何用户访问。
6、这时候安装工作基本完成,可以进行第一个简单例子的测试:
在你的网站目录下建立 index.php文件,并且在(网站目录)/smarty/templates/下建立index.tpl文件,分别输入以下代码
index.php
<?php
//载入Smarty库,如果在php.ini设置了include_path为C:/Apache2/include/Smarty/libs,那么可以直接用include("Smarty.class.php");
//另外不设置include_path,可以直接把Smarty.class.php拷到网站目录,就不用加绝对路径了。
require('C:/Apache2/include/Smarty/libs/Smarty.class.php');

$smarty = new Smarty;

//下面的(你的网站目录)用绝对路径,可以用相对路径(./templates)
$smarty->template_dir='C:/Apache2/htdocs/mysmarty/templates';
$smarty->config_dir='C:/Apache2/htdocs/mysmarty/configs';
$smarty->cache_dir='C:/Apache2/htdocs/mysmarty/cache';
$smarty->compile_dir='C:/Apache2/htdocs/mysmarty/templates_c';
//上面四行为使用Smarty前的必要参数配置

$smarty->assign('name','明天');
$smarty->display('index.tpl');
?>

index.tpl
<html>
<body>
你好,{$name}!
</body>
</html>

7、现在终于可以浏览自己的作品。运行index.php
原创粉丝点击