1、下載Smarty包
可以從官方網站下載:http://smarty.php.net
2、解壓縮Smarty包並找到合適的位置存放,檔案夾名存為是Smarty。將含有Smarty檔案的檔案夾拷貝到某一個目錄下。
下面內容中,我們都是假設你的檔案放在了C:/Apache2/include/Smarty下。
3、找到你的php.ini設定檔修改php.ini的include_path選項,把smarty的庫檔案路徑加上,比如:
include_path = "C:/Apache2/include/Smarty/libs"
提醒一下,php.ini中一共有兩處include_path,一處是Unix下使用的,一處是windows下使用的,要修改windows下使用的:
-------------------------------------------------------------
; Windows: "/path1;/path2"
include_path = "C:/Apache2/include/Smarty/libs"
4、在你的網站目錄下建立一個檔案夾,名字任意,假設叫Smarty:
然後再在這個MySmarty目錄下建立4個檔案夾,templates、configs、template-c和cache。
建立完成之後如下:
(你的網站目錄)/Smarty/templates (這個目錄用來存放模版)
(你的網站目錄)/Smarty/configs (這個目錄用來存放一些配置資訊)
(你的網站目錄)/Smarty/templates-c (這個目錄用來存放編譯檔案)
(你的網站目錄)/Smarty/cache (這個目錄用來存放緩衝)
5、這時候你別忘了把我們上面從一開始到現在建立的四個檔案夾的使用權限設定好。
,在“屬性”中開啟“安全”標籤,在裡面列出了可以訪問這個目錄的使用者列表,
如果沒有web存取權限,則需要添加,把Internet來賓帳戶和啟動IIS進程帳戶兩個帳戶都添加上即可。如果覺得麻煩,可以直接將Everyone用
戶組添加上,允許任何使用者訪問。
6、這時候安裝工作基本完成,可以進行第一個簡單例子的測試:
在你的網站目錄下建立 index.php檔案,並且在(網站目錄)/smarty/templates/下建立index.tpl檔案,分別輸入以下代碼
index.php
<?php
//載入Smarty庫,如果在php.ini設定了include_path為C:/Apache2/include/Smarty/libs,那麼可以直接用include("Smarty.class.php");
//另外不設定include_path,可以直接把Smarty.class.php拷到網站目錄,就不用加絕對路徑了。
require('Smarty.class.php');
$smarty = new Smarty;
//下面的(你的網站目錄)用絕對路徑,可以用相對路徑(./templates)
$smarty->template_dir='E:/site/smarty/templates';
$smarty->config_dir='E:/site/smarty/configs';
$smarty->cache_dir='E:/site/smartycache';
$smarty->compile_dir='E:/site/smarty/templates_c';
//上面四行為使用Smarty前的必要參數配置
$smarty->assign('name','明天');
$smarty->display('index.tpl');
?>
index.tpl
<html>
<body>
你好,{$name}!
</body>
</html>
7、現在終於可以瀏覽自己的作品。運行index.php