Discuz 模板引擎的封裝類代碼_PHP教程

來源:互聯網
上載者:User
主要功能說明

去掉了 Discuz 語言套件的功能
移植 Discuz 模板中所有的功能
添加了自動更新緩衝及生命週期功能
在模板中的使用方法跟Discuz的一樣,所以就不做多餘的說明了,使用前只需要做些簡單的設定就可以了

如果需要使用discuz的語言套件功能,只要去掉template.class.php第172行注釋,並在template.func.php中加上discuz原來的languagevar函數就可以了

點擊下載源檔案

以下是代碼範例:

/**
* 使用樣本
*
* @copyright Copyright (c) 2007-2008 (http://www.tblog.com.cn)
* @author Akon(番茄紅了)
* @license PHP Version 3.0 {@link http://www.php.net/license/3_0.txt}
*/

require_once ('classes/template.class.php');

$options = array(
template_dir' => 'templates/', //指定模板檔案存放目錄
'cache_dir' => 'templates/cache', //指定快取檔案存放目錄
'auto_update' => true, //當模板檔案有改動時重建緩衝 [關閉該項會快一些]
'cache_lifetime' => 1, //緩衝生命週期(分鐘),為 0 表示永久 [設定為 0 會快一些]
);
$template = Template::getInstance(); //使用單件模式執行個體化模板類
$template->setOptions($options); //設定模板參數

/*
// 可以使用以下三種方法設定參數
$template->setOptions(array('template_dir' => 'templates/default/')); //用於大量設定時使用
$template->set('template_dir', 'templates/default/');
$template->template_dir = 'templates/default/');
*/

$testArr = array('testa' => 'a', 'testb' => 'b');
include($template->getfile('test.htm'));
?>

http://www.bkjia.com/PHPjc/319202.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/319202.htmlTechArticle主要功能說明 去掉了Discuz語言套件的功能 移植Discuz模板中所有的功能 添加了自動更新緩衝及生命週期功能 在模板中的使用方法跟Discuz的一樣...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.