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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章