Home > Article > Backend Development > Encapsulation class code of Discuz template engine_PHP tutorial
Main function description
Removed the function of Discuz language pack
Ported all the functions in Discuz template
Added automatic update cache and life cycle functions
How to use it in the template It’s the same as Discuz, so I won’t give any extra explanation. You only need to make some simple settings before use.
If you need to use the language pack function of discuz, just remove template.class.php Chapter 172 Just comment the line and add the original languagevar function of discuz in template.func.php
Click to download the source file
The following is a code example:
/* *
* Usage example
*
* @copyright Copyright (c) 2007-2008 (http://www.tblog.com.cn)
* @author Akon(tomato is red)
* @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/', / /Specify the template file storage directory
'cache_dir' => 'templates/cache', //Specify the cache file storage directory
'auto_update' => true, //Regenerate the cache when the template file is changed [Close this item will be faster]
'cache_lifetime' => 1, //Cache life cycle (minutes), 0 means permanent [Set to 0 will be faster]
);
$template = Template::getInstance(); //Use singleton mode to instantiate the template class
$template->setOptions($options); //Set template parameters
/*
// You can use the following three methods to set parameters
$template->setOptions(array('template_dir' => 'templates/default/')); //Use
$template-> for batch settings ;set('template_dir', 'templates/default/');
$template->template_dir = 'templates/default/');
*/
$testArr = array(' testa' => 'a', 'testb' => 'b');
include($template->getfile('test.htm'));
?>