个人感觉discuz模板引擎实现了php和html在一定程度上的分离,缓存机制也比较好,header,footer,复用,
下面的那个链接是我利用phpchina会员xing393939剥离出来的Discuz模板引擎实现的一个在面,放在空间里面做研究,更加具体的解释,移步这里Discuz模板说明{转}
下面是我写的个实例,利用“php+discuz模板引擎”写得蓝屏画面来恶搞http 错误代码,带缓存机制:
http://ihipop.info/i-service/disczu_template_engine/shcode.php
http://ihipop.info/i-service/disczu_template_engine/shcode.php?code=110
http://ihipop.info/i-service/disczu_template_engine/shcode.php?code=404
http://ihipop.info/i-service/disczu_template_engine/shcode.php?code=403
http://ihipop.info/i-service/disczu_template_engine/shcode.php?code=500
shcode.php
[php]<?php
define('MBLOG_ROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);
define('IN_MBLOG', TRUE);
$tpldir = './templates/error'; //模板文件目录
$styleid = 1; //模板id号用,来区别不同的目录的模板
$tplrefresh = 1; //是否自动刷新
require_once './template.func.php'; //引用长标签或者短标签函数库
$language = include MBLOG_ROOT.$tpldir.'/language.php'; //language.php的编码需要和博客系统的编码一致
//下面开始不属于基本设置
$code = isset($_GET['code']) ? $_GET['code'] : 1;
//isset()函数检查通过GET传递过来的变量是否被赋值,若没有被赋值,该变量被赋值为1
$arr = array('Is', 'going', 'to', 'restart', 'in', '20s,' ,'or', 'you',' can', 'click', '<a href="/">here</a>','to restart your browser immediately.');
//这里只是为了介绍下模板里面的loop语法
//这里只是为了演示动态标题栏
function codetolang($code){
$code = error_.$code;
//php的字符串运算符是英文句号.
$code = languagevar($code);
if(preg_match("/^(!).*(!)$/",$code)){
echo languagevar(error_default);
}else{
echo $code;
}
}
//演示函数
include template('error');
?>
[/php]
header.htm
[php]<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />
<META content=20;url=/ http-equiv=refresh />
<title>{eval codetolang($code)}</title>
<link type="text/css" href="templates/error/css/common.css" rel="stylesheet" />
<script type="text/javascript" src="templates/error/js/main.js"></script>
</head>
<body>[/php]
error.htm
[php]{subtemplate header}
<p>{lang problem}</p>
<p>{eval codetolang($code)}</p>
<p>{lang isfirst}</p>
<p>{lang diskspace}</p>
<p>{lang bios}</p>
<p>{lang info}</p>
<p>{lang stop}</p>
<p>{lang contact}</p>
<p>{lang dump}</p>
<p>{lang dumpcomp}</p>
<p>{lang contact}</p>
<ul>
{loop $arr $myval}{$myval}
{/loop}
</ul>
{subtemplate footer}[/php]
footer.htm
[php]</body>
</html>
[/php]
language.php
[php]
<?php
return array(
'error_400' => '400 Bad Request',
'error_401' => '401 Unauthorized',
'error_403' => '403 Forbidden',
'error_404' => '404 Not Found',
'error_405' => '405 Method Not Allowed',
'error_406' => '406 Not Acceptable',
'error_407' => '407 Proxy Authentication Required',
'error_408' => '408 Request Timeout',
'error_409' => '409 Conflict',
'error_410' => '410 Gone',
'error_412' => '412 Precondition Failed',
'error_414' => '414 Request-URI Too Long',
'error_500' => '500 Internal Server Error',
'error_502' => '502 Bad Gateway',
'error_503' => '503 Service Unavailable',
'error_504' => '504 Gateway Timeout',
'error_default' => 'Uknown Error',
'problem' => 'A problem has been detected and Browser has been shut down to prevent damage to your Mood.',
'isfirst' => 'If this is the first time you ve seen this stop error screen, refresh your browser. If this screen appears again, follow these steps:',
'diskspace' => 'Check to be sure you have adequate disk space, if a driver is identified in the stop message, disable the driver or check with the manufacturer for driver updates. Try changing video adapters.',
'bios' => 'Check with your hardware vendor for any BIOS updates. Disable BIOS memory options such as caching or shadowing. If you need to use safe Mode to try again, restart your browser, press Ctrl+Shift+Delete to access Clear recent History, and then beside Time range to clear, click Everything, and then select clear now.',
'info' => 'Technical information:',
'stop' => '*** STOP:0×00000001( 0×00000000,0×00000001, 0×00000002,0×00000003 )',
'dump' => 'Beginning dump of physical memory',
'dumpcomp' => 'physical memory dump complete',
'contact' => 'Contact your system administrator or technical support group for further assistance.',
);
?>
[/php]
好处:只需要剪辑language.php就可以实现程序的多语言化和新Error Code的添加,对于这个例子来说,虽然编写的时候复杂了点(完全有更加简单的写法),但是对于做一个大型系统和做模板和语言包的人来说,非常方便!,可以将代码重复降低到最少!
这个好,技术强人
源代码不是都帖出来了吗?
尽然么的实例下载啊。。。