Smarty安装和入门教程

来源: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

 

转载于:https://www.cnblogs.com/kangshifu/archive/2008/08/08/1263675.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值