页:
[1]
| chinahtml | 2008-3-1 12:27 PM |
|
从Discuz中抠出的模板类
从网上看到几个关于dz的模板类,但都不咋合适,
这个也是改自网上,在php4.4.7下测试暂时没发现问题。。
用得上就拿去,里面还有一个示范。;P;P
[php]/************************************************************
Discuz 模板引擎类
1、去掉了 Discuz 语言包的功能
2、移植 Discuz 模板中所有的功能
3、添加了自动更新缓存及生命周期功能
************************************************************/
header("Content-Type: text/html; charset=utf-8");
require_once ('classes/template.class.php');
$options = array(
'template_dir' => 'templates/', //指定模板文件存放目录
'cache_dir' => 'templates/cache/', //指定缓存文件存放目录
'auto_update' => true, //当模板文件有改动时重新生成缓存 [关闭该项会快一些]
'cache_lifetime' => 1, //缓存生命周期(分钟),为 0 表示永久 [设置为 0 会快一些]
);
$template = new Template(); //使用单件模式实例化模板类
$template->setOptions($options); //设置模板参数
/*
// 可以使用以下三种方法设置参数
$template->setOptions(array('template_dir' => 'templates/default/')); //用于批量设置时使用
$template->set('template_dir', 'templates/default/');
$template->template_dir = 'templates/default/');
*/
$testArr = array('testa' => 'KKKKKKKKKKKKKK', 'testb' => 'YYYYYYYYYYYYYY');
$www='www.phpx.com/happy';
$ifopen=-1;
$itemlist=array(
"a"=>array(
"color"=>"red",
"size"=>"big"
),
"b"=>array(
"color"=>"green",
"size"=>"small"
)
);
$str =array(
$str1 =array(
"url"=>"/a/b/c/2008-1-28.html",
"title"=>"Discuz 模板引擎类",
"author"=>"chinahtml",
"time"=>"2008-1-28 12:12:50"
),
$str2 =array(
"url"=>"/a/b/c/2008-1-29.html",
"title"=>"Discuz 6.0下载",
"author"=>"discuz",
"time"=>"2008-1-29 13:18:15"
),
$str3 =array(
"url"=>"/a/b/c/2008-1-30.html",
"title"=>"喜悦国际村真喜悦",
"author"=>"sadly",
"time"=>"2008-1-30 23:12:24"
)
);
function getstr($string)
{
if ($string==1)
{
return $str_array=array(array(
"url"=>"/a/b/c/2008-1-29.html",
"title"=>"Discuz 6.0下载",
"author"=>"discuz",
"time"=>"2008-1-29 13:18:15"
));
} elseif ($string==2) {
return $str_array=array(array(
"url"=>"/a/b/c/2008-1-30.html",
"title"=>"喜悦国际村真喜悦",
"author"=>"sadly",
"time"=>"2008-1-30 23:12:24"
));
}
}
include($template->getfile('test.htm'));[/php] |
| lyhiving | 2008-3-1 01:36 PM |
|
| 不错,不过明显复杂了些~~~ |
| xiaotao5 | 2008-3-2 02:22 AM |
|
| 太复杂了,还是我的简单 |
| angeloisme | 2008-3-3 09:11 AM |
|
| 说实在的,这事06年的时候我干过. |
| gaoshikao | 2008-3-13 06:44 AM |
|
恩 收下
比DZ本身的多了一个自定义参数的接口
DZ的摸版使用起来确实方便,最起码不会写50行的assign() |
|
[url]http://www.phpx.com/happy/viewthread.php?tid=141343&highlight=%2Bisno[/url]
俺也发过 嘿嘿 |
|
| 学习了////////////////////////////////////////// |
| aultoale | 2008-6-11 02:20 AM |
|
。。。。
到這裏來了。。 |
| bailywen | 2008-6-16 01:46 AM |
|
| 收了.谢了 |
Powered by Discuz! Archiver 6.1.0
© 2001-2006 Comsenz Inc.
Processed in 0.006599 second(s), 2 queries |