Smarty3.1.8 安装

 应用环境:Winsows7 IIS + PHP5.5.12 + Smarty3.1.8

 

1. IIS 及 PHP 安装,参照《php手册》,这里不做细表。

2. 假定应用目录为 C:\inetpub\wwwroot\smarty,解压缩Smarty3.1.8包,将libs文件夹拷贝至应用目录下;

3. 在应用目录下新建一下几个文件夹:

    templates(用于存放模版的目录) 

    templates_c(用于存放编译后文件的目录) 

    cache(用于存放缓存的目录)

    config(用于存放配置的目录) 

4. 设置应用目录的权限,允许当前用户对应用目录及其子文件/子文件夹的读写操作,Internet来宾帐户和启动IIS进程帐户两个帐户也要加上读写权限。(重要)

5. 在应用目录下新建 smarty.php 文件,内容如下:

<?php

    @require("libs/Smarty.class.php");

    $smarty = new smarty();

    $smarty->template_dir="templates";  //指定模版存放目录

    $smarty->compile_dir="templates_c";  //指定编译文件存放目录

    $smarty->config_dir="config";  //指定配置文件存放目录

    $smarty->cache_dir="cache";  //指定缓存存放目录

    $smarty->caching=false;  //关闭缓存(设置为true表示启用缓存)

    $smarty->left_delimiter="<{";  //指定左标签

    $smarty->right_delimiter="}>";  //指定右标签

?>

 

6. 在templates文件夹下新建 index.tpl 模板文件,内容如下:

<html>

<head>

    <title>{$title}</title>

    <meta http-equiv="Content-Type" content="text/html;charset=gbk" />

</head>

<body>

    <span>你好,{$name}</span>

</body>

</html> 

 

7. 在应用目录下新建 index.tpl 模板文件,内容如下:

<?php

    @require("smarty.php");

    $smarty->assign('name','哈哈镜');

    $smarty->assign('title','smarty安装测试');

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

?>

 

8. 访问http://localhost/smarty/index.php ,显示以下窗口说明安装完成:

你好,哈哈镜

 

posted @ 2014-05-30 09:42  陆吾  阅读(286)  评论(0编辑  收藏  举报