search
Homephp教程php手册Discuz 模板引擎的封装类代码

Discuz 模板引擎的封装类代码

Jun 13, 2016 pm 12:27 PM
discuzmaincodeFunctionBaggoencapsulationenginetemplateofkindlanguageillustrate


主要功能说明

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

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version