Smarty3.1.8 安装

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

 

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

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

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

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

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

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

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

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

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

<?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 ,显示如下窗口说明安装完成:

你好,哈哈镜

相关文章
相关标签/搜索