蓝氏家族PHP template进阶学习
用PHP Template Block技术实现分层我以前不知道像公社论坛phpbb2的论坛分那么多的类别,而且每个类别还有那么多的小区域是如何形成的>_<还以为是用html语言一点点的加入的。后来参看了PHPlib的doc文档中有关set_block的template用法才恍然大悟:原来这种树形结构,如下图:
[img]http://www.cs.wust.edu.cn/leslie/block.jpg[/img]
是用block实现的,有点像可视化C/C++语言中TreeView控件的定义类似,提及了句柄这个概念。
先用任何可视化网页编辑工具,或者用quanta、bluefish等,甚至就用记事本编写一个名为block.htm的网页模板。
[runcode]<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>{SITENAME}</title>
</head>
<body>
<table width="100%" border="1">
<tr>
<th scope="row"><div align="center">
<h1>{FORUM}</h1>
</div></th>
<td> <div align="center">
<h1>{TOPICS} </h1>
</div></td>
<td> <div align="center">
<h1>{POSTS} </h1>
</div></td>
<td><div align="center">
<h1>{LAST_POST}</h1>
</div></td>
</tr>
<!-- BEGIN category_list -->
<tr>
<th height="28" scope="row"><div align="left">
<h2>{CATEGORY}</h2>
</div></th>
<td> </td>
<td> </td>
<td> </td>
</tr>
<!-- BEGIN forum_name_list -->
<tr>
<th height="49" scope="row"><h3>{FORUM_NAME}</h3>
<h5>{DES}</h5></th>
<td> </td>
<td> </td>
<td> </td>
</tr>
<!-- END forum_name_list -->
<!-- END category_list -->
</table>
</body>
</html>
[/runcode]
注意不要忘记写<!-- BEGIN … -->和<!-- END … -->标签,否则PHP会不知道在何处分block^_^
上面block.htm的可视化页面,如下:
然后用任意文本编译器编写调用block.htm网页模板的PHP文件block.php
[php]<?php
/*在根文件夹下创建includes文件夹,把下载来的PHPlib/php里的template.inc
copy + paste到其中*/
include('./includes/template.inc');
/*在根文件夹下创建templates文件夹,把上面编写的block.htm模板放在templates文件夹中*/
$template = new Template('./templates');
$category = array("公告","休闲");
$forum_name = array(array("最新消息","处罚通知"),array("音乐","贴图","灌水"));
$des = array(array("公布论坛最新消息","体现违规用户的ID号"),array("流行音乐","蓝氏家族的片片","水园养大的孩子"));
$template->set_file(array(
'body' => 'block.htm'
)
);
/*设置block*/
$template->set_block('body','category_list','c');//第一层block的句柄是body(template的输出句柄)
$template->set_block('category_list','forum_name_list','f');//第二层block的句柄是category_list(第一层的block)
$template->set_block('category_list','des_list','d');//第二层block的句柄是category_list(第一层的block)
for($i=0;$i<count($category);$i++){
/*清空第二层block的值,屏蔽掉此句的结构请自己尝试*/
$template->set_var('f');
$template->set_var(array(
'CATEGORY' => $category[$i]
)
);
for($j=0;$j<count($forum_name[$i]);$j++){
$template->set_var(array(
'FORUM_NAME' => $forum_name[$i][$j],
'DES' => $des[$i][$j]
)
);
$template->parse('f','forum_name_list',true);
}
$template->parse('c','category_list',true);
$template->parse('d','des_list',true);
}
$template->set_var(array(
'SITENAME' => "涩兔子block测试",
'FORUM' => "论坛",
'TOPICS' => "话题",
'POSTS' => "发言",
'LAST_POST' => "最后回复"
)
);
$template->pparse('output','body');
?>
[/php]
好了,在浏览器里输入[url]http://localhost/.../block.php[/url]
表现的block.php页面如下:
实际上$category = array("公告","休闲");这些block中的信息都是由后台数据库提供的,所以还需要了解更多的知识才能see php forum backwards & forwards^_^
.
[size=4]长期收购网站,论坛顶部广告位 [/size][size=4][/size]
[size=4]要求投放图片广告,其他无要求[/size]
[size=4][/size]
[size=4][color=red]800元/月 为表诚意 先给钱 后上广告[/color][/size]
[size=4][/size]
[size=4][color=blue]可投放广告的站长加 QQ:463025898[/color][/size]
太牛了!几乎没人逃得过的超准思维定向测试!
切记要慢慢,请不要第一次就看完了全部!一定要慢慢的往下看!这样你才能真的体会到真的很很诡异的喔!要以最快速的时间心算所看到的数学程序,然后回答问题!开始啰!往下走,并答题吧!
2+2=?
************
************
************
************
************
************
************
4+4=?
************
************
************
************
************
************
************
************
8+8=?
************
************
************
************
************
************
************
************
16+16=?
************
************
************
************
************
************
************
************
快!随便在12至5的中间挑一个数字!
************
************
************
************
************
************
************
挑了吗?现在继续往下….
************
************
************
************
************
************
************
************
你挑的数字是”7″,对吧!
************
继续作下一个实验!跟着下列叙述并且快速回答问题!算算看啰!
1+5
************
************
************
************
************
************
************
************
2+4
************
************
************
************
************
************
************
************
3+3
************
************
************
************
************
************
************
************
4+2
************
************
************
************
************
************
************
************
5+1
************
************
************
************
************
************
************
************
************
现在持续默念”6″这个数字15秒,然后往下卷动画面!
************
************
************
************
************
************
************
************
快!想一个蔬菜的名字!然后继续往下卷动作!
************
************
************
继续卷动…….
************
************
************
************
************
************
************
************
************
************
************
************
你想的是大白菜,对吧!如果不是,你是占2%可以在正常情形下还可以有余力思考别的事的少数人口,98%的人会回答大白菜。诡异哦!听说这个测验是从爱丽丝梦游仙境中兔子国翻译的……
再来做一个测试> > > > >你是否正常﹖
> > > > >請跟著以下的指示,盡快地回答以下的問題,但要先完成一个問題才回答下一個。你不需要寫下答案,只要心算便可。
15+6是多少?
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
3+56
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
89+2
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
12+53
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
75+26
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
75+26
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
25+52
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
63+32
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
123+5
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
快!!!心想一種工具和一種顏色!
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
> > > >>
你剛剛想的是否紅红色的鎚子(chui zi)﹖
> > > >>如果答案不是的話,你就是2%的與別人不同的人∕不正常人,通常98%的人做會回答紅色的鎚子怎么样!准确吧!
继续作下一个实验!
跟着下列叙述并且快速回答问题!
算算看啰!
************
************
3+78=?
************
************
************
************
************
************
1+5
************
************
************
************
************
************
************
2+4
************
************
************
************
************
************
************
3+3
************
************
************
************
************
************
************
4+2
************
************
************
************
************
************
************
5+1
************
************
************
************
************
************
************
现在持续默念”6″这个数字15秒,然后往下卷动画面!
************
************
************
************
************
************
************
快!说出一种水果的名字!然后继续往下卷动作!
************
************
************
************
************
************
************
继续卷动…….
************
************
************
************
************
8+329=?
************
************
************
************
************
************
**********
27+7=?
***********
快卷动
************
************
************
************
************
************
说出一个面部器官
***********
***********
************
************
************
************
************
************
************
************
************
说出一种家禽的名字
************
************
************
************
************
************
************
************
哈哈,是苹果和鼻子和鸡,对不对?
不准耍耍赖~~~~~呵呵~~~~~~~
[url=http://www.hengda86.com/]灌浆料[/url],[url=http://www.hengda86.com/]水泥灌浆料[/url],[url=http://www.hengda86.com/]灌浆料标准[/url],[url=http://www.hengda86.com/]灌浆材料[/url],[url=http://www.hengda86.com/]cgm灌浆料[/url],[url=http://www.hengda86.com/]灌浆料价格[/url],[url=http://www.hengda86.com/]灌浆料生产[/url],[url=http://www.hengda86.com/]40灌浆料[/url],[url=http://www.hengda86.com/]基灌浆料[/url],[url=http://www.hengda86.com/]收缩灌浆料[/url],[url=http://www.hengda86.com/]次灌浆料[/url],[url=http://www.hengda86.com/]二次灌浆料[/url],[url=http://www.hengda86.com/]灌浆水泥[/url],[url=http://www.hengda86.com/]灌浆机[/url],[url=http://www.hengda86.com/]混凝土灌浆[/url],[url=http://www.hengda86.com/]灌浆加固[/url],[url=http://www.hengda86.com/]灌浆方法[/url],[url=http://www.hengda86.com/]灌浆施工[/url],[url=http://www.hengda86.com/]灌浆管[/url],[url=http://www.hengda86.com/]灌浆设备[/url],[url=http://www.hengda86.com/]结构料[/url],[url=http://www.hengda86.com/]胶料[/url],[url=http://www.hengda86.com/]裂缝灌浆[/url],[url=http://www.hengda86.com/]高强无收缩灌浆料[/url]
页:
[1]