主页面zhuye.php
<html>
<head>
<meta charset='utf-8'/>
</head>
<body>
<form action="__URL__/add" method='post'>
发表一下今天的心情吧:<br/>
<textarea cols='40' rows='10' name='content'></textarea><br/>
用户名:<input type="text" name="username"/><input type="submit" value="发表"/>
</form>
</body>
</html>
发表后跳转的页面,tuo.php
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>腾讯说说</title>
<style>
#message{
width:800px;
height:100%;
background-color:#FFC;
font-size:15px;
color:#666666;
}
</style>
</head>
<body>
<h1>模拟腾讯说说</h1>
<div id="message">
<volist name='list' id='vo'>
<form method="post" action="__URL__/reply">
<table width="100%" border="0">
<tr>
<php>
for($i=0;$i<$vo['count'];$i++){
echo '<td></td>';
}
</php>
<td>
{$vo.name}:{$vo.content}<br>
{$vo.pubtime} <a href="javascript:void(0)" onclick="show({$vo.id})">回复</a>
<div id="reply{$vo.id}" style="display:none">
<input type="text" name="content"/>
<input type="submit" value="提交"/>
<input type="hidden" name='path' value="{$vo.id},{$vo.path}"/>
</div>
</td>
</tr>
</table>
<input type="hidden" name="" value="" /></form>
<br>
</volist>
</div>
</body>
<script type="text/javascript">
function show(id){
document.getElementById('reply'+id).style.display = 'block';
}
</script>
<div><a href='__URL__/zhuye'>返回</a></div>
</html>
动作MessageAction.class.php
<?php
class MessageAction extends Action {
public function zhuye(){
$this->display();
}
public function add(){
header('Content-Type:text/html;charset=utf-8');
//获得模型
$model=D('Message');
//处理数据
$data['name']=$_POST['username'];
$data['pubtime']=Date('Y-m-d H:i:s');
$data['content']=$_POST['content'];
$data['pid']=0;
$data['path']=0;
if ($model->add($data)){
$this->success('发表成功','__URL__/two');
}}
public function two(){
$model = D('Message');
$list = $model->field("id,name,content,pubtime,path,concat(path,'-',id)as dpath")->order('dpath')->select();
//缩进显示内容
//如何通过级别来显示缩进的空格,我是通过统计path字段的数量
foreach($list as $key=>$value){
$list[$key]['count'] = count(explode('-',$value['path']));
}
$this->assign('list',$list);
$this->display();
}
public function reply(){
$model=D('Message');
$data['name']='李四';
$data['content']=$_POST['content'];
$data['pubtime']=Date('Y-m-d H:i:s');
$path=$_POST['path'];
//利用拼接实现无限极分类
$arr=explode(',',$path);
$data['path']=$arr[1].'-'.$arr[0];
if ($model->add($data)){
$this->success('成功',__URL__/two);
}
else {
$this->error('失败');
}
}
}
?>