tp论坛 分页(三)
***********分頁的使用*************
1:分頁使得信息的顯示更加條例,
2:在detail()
public function detail($id){
$m=M('board');
//獲取變量的整數值
$id=intval($id);
$board=$m->where("id=$id")->select();
$this->assign('board',$board[0]);
$n=M('post');
$count=$n->where("board=$id")->count();
$page=new \Think\Page($count,8);
$show=$page->show();
$post=$n->where("board=$id")->limit($page->firstRow.','.$page->listRows)->select();
$this->assign("post",$post);
$this->assign('page',$show);
$this->display();
}
3:在detail.html中:
<body>
<h2>簡易的BBS</h2>
<h3>{$board.name}<h3>
<table border=1>
<foreach name='post' item='vo'>
<tr>
<td>第{$key}貼</td>
<td><a href="#">{$vo.text}</a></td>
<td>樓主:{$vo.author}</td>
</tr>
</foreach>
</table>
{$page}
</body>
第四節:帖子的模塊的建立和完善
1:我們的發帖通常分為主題帖和回復貼,我們這里用own來區分,如果own為0,則為主題帖,如果是其他帖子的id則為回復貼
2:我們這里需要實現兩個功能,一個是看帖,一個是發帖,看帖功能我們在index里面實現,發帖功能我們在add里面實現
3:我們先在application目錄下的home目錄下建postController.class.php文件
4:在view下添加post
**********首先添加測試數據*********
public function addpost($id){
$m=M('post');
$data=array();
$data[]=array('board'=>1,'text'=>'隱形php,值得關注','own'=>$id,'author'=>'xinqi');
$data[]=array('board'=>1,'text'=>'啦啦啦,值得關注','own'=>$id,'author'=>'xinqi');
$data[]=array('board'=>1,'text'=>'嘻嘻嘻,值得關注','own'=>$id,'author'=>'xinqi');
$data[]=array('board'=>1,'text'=>'哈哈哈,值得關注','own'=>$id,'author'=>'xinqi');
$data[]=array('board'=>1,'text'=>'丁丁到,值得關注','own'=>$id,'author'=>'xinqi');
$data[]=array('board'=>1,'text'=>'哦哦哦哦哦p,值得關注','own'=>$id,'author'=>'xinqi');
$data[]=array('board'=>1,'text'=>'你看,值得關注','own'=>$id,'author'=>'xinqi');
$m->addALL($data);
echo '執行完畢';
}
************看帖功能的實現*****************
public function index($id){
$m=M('post');
$owner=$m->where("own=0 and id=$id")->find();
$this->assign('owner',$owner);
$count=$m->where("own=$id")->count();
$page=new \Think\Page($count,8);
$show=$page->show();
$post=$m->where("own=$id")->limit($page->firstRow.','.$page->listRows)->select();
$this->assign('post',$post);
$this->assign('page',$show);
$this->display();
}
?
<body>
<table border=1>
<tr><td width=200>樓主</td><td width=200>{$owner.text}</td><td width=200>{$owner.author}</td></tr>
<foreach name="post" item="vo">
<tr><td>第{$key}樓</td>
<td>{$vo.text}</td>
<td>{$vo.author}</td>
</tr>
</foreacch>
</table>
{$page}
<form method ="post" action="__ROOT__/Home/Post/add" role="form">
<input type="text" id="name" name="text" placeholder="請輸入內容"/>
<input type="hidden" name="board" value="<?php echo $owner['board']?>"/>
<input type="hidden" name="own" value="<?php echo $owner['id']?>"/>
<input type="checkbox" name="alone">是否作為主題帖
<button type="submit"> 發表</button>
</form>
</body>
?
轉載于:https://www.cnblogs.com/yanran/p/4928332.html
總結
以上是生活随笔為你收集整理的tp论坛 分页(三)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (软件工程复习核心重点)第七章软件维护-
- 下一篇: (王道408考研操作系统)第三章内存管理