[精讚] [會員登入]
2208

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] UTF8中取出字串中特定的字數 要將字串,例如資料庫取出的TEXT,取出特定的字數

[PHP] 類別的繼承及建構子和解構子 PHP 類別的繼承及建構子和解構子

[PHP] 如何寫callback function 召回函數(回呼函數) PHP如何寫召回函數或回呼函數(callback function)?

[PHP]解決ksort新增的SORT_NATURAL|SORT_FLAG_CASE方法 php>=5.4中ksort函數多了SORT_NATURAL 和 SORT_FLAG_CASE 旗標,對舊版的PHP中要怎麼辦?

[Centos 6& 7] 安裝php-geoip php-geoip是PHP由domain、ip查詢城市國家資料非常強的函式

[PHP] 字串編碼及解碼函式 為何要將字串編碼?理由很簡單,就是不要讓人家輕易的知道字串內容是什麼。例如點選分頁時,我們常會用這樣的連結: index

隨機好文

[Windows7] 移除IE10及移除IE11 Windows7 不得已的情況要移除IE11或IE10怎麼做?

維修冰箱 維修冰箱

設計的工作絕不接受比價 拿買陽春麵的價格想買牛肉麵,寧願倒掉也不賣

讓radio box 或checkbox 好按 在行動裝置下,radio box及checkbox變得很難按得到

[Mysql] 資料型態int, float, double, text, char, varchar, blob大小 Mysql中資料型態int, float, text, char, varchar, blob大小