[精讚] [會員登入]
2066

Smarty安裝

smarty 是著名的樣版引擎,非常的好用,用多了突然發現拿掉smarty反而不會寫php了,以下是安裝過程..

分享此文連結 //n.sfs.tw/10112

分享連結 Smarty安裝@新精讚
(文章歡迎轉載,務必尊重版權註明連結來源)
2019-10-24 08:51:01 最後編修
2016-10-31 07:47:05 By 張○○
 

自動目錄

程式需求

Smarty requires PHP 4.0.6 or later.

安裝

一、下載 http://www.smarty.net/download.php 及解壓,例如解壓到 /path/to/smarty/

二、建立目錄於解壓的smarty 目錄中 "templates", "configs", and   "templates_c", "cache"

$ chmod 777 cache/
$ chmod 777 templates_c

三、SELinux打開寫入權限

$ chcon -t httpd_sys_rw_content_t /path/to/smarty/templates_c -R
$ chcon -t httpd_sys_rw_content_t /path/to/smarty/cache -R

四、PHP程式的引用

include "path/to/smarty/Smarty.class.php";      //讀入SMARTY函式庫
初始宣告 Smarty() 類別
$view = new Smarty();

五、Smarty 的常數設定

$SITE_ROOT = "smarty/";

$view->template_dir = $SITE_ROOT . "/templates/";
$view->compile_dir = $SITE_ROOT . "/templates_c/";
$view->config_dir = $SITE_ROOT . "/configs/";
$view->cache_dir = $SITE_ROOT . "/cache/";
$view->left_delimiter = '{{';
$view->right_delimiter = '}}';

六、樣版變數的指定

以下範例指定樣板中變數 $test 的值
$view->assign("test","This is a Test String");
以下範例在網頁中顯示樣板 index.tpl
$view->display('index.tpl');

七、樣板的使用範例

index.tpl

<body>
這是一個範例 {{$test}} 
</body>

整理 2009-02-21 01:55:48

END

你可能感興趣的文章

[PHP] 2個程式的觀念 整理2個PHP的程式觀念,參考參考。

[Smarty5] 如何在樣版中使用php本身的函式 解決 smarty5版後不能直接叫用 php函式的問題

PHP 數字加解密函式 自寫的數字加解密,勉強用

[PHP8] 使用autoload autoload+ namespace +use 到了php7之後,namespace和use越來越重要,此篇整理autoload和namespace、use的結合使用。

[CodeIgniter 3] 修改或插入資料時遇到函數的處理 CI3 中要新增或修改的資料中如果有 now()這類的函數,要怎麼處理?

PHP程式經驗 #2 -- print和echo的差異 常在寫php的人一定會想知道echo和print這兩個函數有什麼不一樣 驗證 1. 比較print 和echo 函式的執

隨機好文

HP SAS硬碟leds燈號說明 HP SAS硬碟leds燈號(hp g7/g6系統適用)說明

UTF-8 BOM (Byte Order Mark) 的問題 在 Michael Kaplan 那看到 Every character has a story #4: U+feff

精讚的版面變化 ▓此文僅作為舊文的記錄▓ 這篇文章為了紀念改版完成而撰寫。 原本的部落格是民國97年的作品,那時還是用舊有的技術來寫,很

APACHE的記錄檔格式 LogFormat 語法 在APACHE中有定義一些記錄的語法模版 在 /etc/httpd/conf/httpd.conf 中: LogForm

[CodeIgniter 3] 資料庫的使用方法整理2/2 CI3 承襲 CI2,有很多的builder class可以用,依各人的使用習慣,有人喜歡一堆sql字串,有人喜歡用helper