Home >Backend Development >PHP Tutorial >Encapsulation class code of Discuz template engine_PHP tutorial

Encapsulation class code of Discuz template engine_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:51:15914browse


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'));
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319202.htmlTechArticleMain function description Removed the functions of the Discuz language pack and transplanted all the functions in the Discuz template. Added automatic update cache and life The period function is used in the template in the same way as Discuz...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn