[精讚] [會員登入]
1306

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中文字轉成10進位或16進位數值 原本為了處理 preg_match 中文字的問題[2],用php把中文字轉換成10進位和6進位的數值編碼

[PHP7] 利用Memcached 儲存 Session Memcached+ PHP7,利用Memcached 儲存 Session。

[phpmyadmin] 錯誤:您應升級到 MySQL 5.5.0 或更新版本 使用phpmyadmin4出現錯誤:您應升級到 MySQL 5.5.0 或更新版本的解決方式

[PHP] 陣列排序 sort, ksort, asort, usort... 簡單的記錄PHP的陣列排序,因為常常會用到。

設定Google analytics API #1 -- Google網站上的設定 讓你的網站能夠存取你的Google analytics上面的資料

[PHP] 位元運算 (Bitwise operation)及和PERL比較 PHP 的位元運算,及和PERL比較整理

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

沒有非誰做不可的事,也沒有不可被取代的人 沒有非誰做不可的事,也沒有不可被取代的人

如何在linux下執行java 原生的java應用程式可以使用簡單的方法在console下面寫出來,適合作簡單的應用

[札記] 2016.7~12月札記 札記,只是札記

[CodeIgniter3] 解決無法上傳特定檔案(.sb2)的問題 上傳時出現The filetype you are attempting to upload is not allowed,要怎麼解決?

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