應用環境: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 ,顯示如下窗口說明安裝完成:
你好,哈哈鏡