您的位置:首页 > 其它

Smarty安装和入门教程

2008-08-08 13:15 369 查看
来源:http://www.study-code.com/php-delphi/php/70545.htm

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

下面内容中,我们都是假设你的文件放在了D:\Appserv\www\Smarty下。

3、找到你的php.ini配置文件修改php.ini的include_path选项,把smarty的库文件路径加上,比如:

include_path = "D:\Appserv\www\Smarty\libs"

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

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

; Windows: "\path1;\path2"

include_path = "D:\Appserv\www\Smarty\libs"

4、在你的网站目录下创建一个文件夹,名字任意,假设叫Mysmarty:

然后再在这个MySmarty目录下创建4个文件夹,templates、configs、template-c和cache。

创建完成之后如下:

(你的网站目录)/Mysmarty/templates (这个目录用来存放模版)

(你的网站目录)/Mysmarty/configs (这个目录用来存放一些配置信息)

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

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

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

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

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

户组添加上,允许任何用户访问。

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

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

index.php

<?php

//载入Smarty库,如果在php.ini设置了include_path为D:\Appserv\www\Mysmarty\libs,那么可以直接用include("Smarty.class.php");

//另外不设置include_path,可以直接把Smarty.class.php拷到网站目录,就不用加绝对路径了。

require('D:\Appserv\www\Smarty\libs\Smarty.class.php');

$smarty = new Smarty;

//下面的(你的网站目录)用绝对路径,可以用相对路径(./templates)

$smarty->template_dir='D:\Appserv\www\Mysmarty\templates';

$smarty->config_dir='D:\Appserv\www\Mysmarty\configs';

$smarty->cache_dir='D:\Appserv\www\Mysmarty\cache';

$smarty->compile_dir='D:\Appserv\www\Mysmarty\templates_c';

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

$smarty->assign('name','明天');

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

?>

index.tpl

<html>

<body>

你好,{$name}!

</body>

</html>

7、现在终于可以浏览自己的作品。运行index.php
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: