[精讚] [會員登入]
1826

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的程式觀念,參考參考。

[PHP] IPv6檢查IP是否在某個網段內 mtachcidr6 要檢查IPv6是否在某個IPv6的網段內?

[CodeIgniter3] CI3 Session 失敗的問題 這次把我的程式放到Centos8,結果sesssion 一直沒作用,真的不知道發生了什麼事?

[PHP] preg_match 的貪婪和不貪婪比對 在php preg_match中預設是採用貪婪比對,太貪婪反而不符合需要,因此得採用「非貪婪比對」...

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

[PHP] CodeIgniter 3+pure+smarty安裝及環境設置1/2 PHP framework CodeIgniter 3+ pure CSS +smarty Template Engine的整合

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

Linux shell 的date表示法 linux下SHELL中的date表示法

[bc] linux 的計算機 bc 設定小數位數、計算π、次方根 linux 的計算機 bc 設定小數位數、計算π、次方根

[MAC] 安裝APACHE+PHP OS Darwin OpenIDMac1deAir 15.6.0 Darwin Kernel Version 15.6.

[AS3] 變數型態 基本類型宣告 as3 有下列幾種基本類型:string, int, number, object, boolean, n

在Centos7 下安裝 Wildfly10 wildfly以前叫JBoss,2014.11.20改名叫Wildfly,起始版本是Wildfly8,現在已經出到Wil