一、首先需要在MsgManage控制器中加入分页方法
知识点:
1、count函数的试用
2、Page类实例化操作及相关参数了解
3、limit函数了用
4、show函数了解
编辑文件admin/Lib/Action/MsgManageAction.class.php
代码如下:
class MsgManageAction extends CommonAction {
public function index(){
import(\'ORG.Util.Page\');
//import调用的是message/ThinkPHP框架目录下的扩展包Extend/Library/ORG/Util/中的Page.class.php类文件
$count = M(\'board\')->count();
//调用board库,取出所有数据条数
$page = new Page($count ,10);
//实例化Page类,其中第一个参数为显示条数的总数,每次取出十条,也就是下面$page->listRows的值
$limit = $page->firstRow . \',\' . $page->listRows;
//$page->firstRow为查找的起始条数,默认为0,如果$page->listRows为10,那么第2页的$page->firstRow就为10,以此类推
$board = M(\'board\')->order(\'time DESC\')->limit($limit)->select();
//注意,这里较之前的版本添加了->limit($limit)
$this->board = $board;
$this->page = $page->show();
//将$page->show()通过show方法解析$page内容显示并赋值给模板变量,供模板调用
$this->display();
}
Public function delete(){
$id = I(\'id\',\'\',\'intval\');
if(M(\'board\')->delete($id)){
$this->success(\'删除成功\',U(\'index\'));
}else{
$this->error(\'删除失败\');
}
}
}
本文地址:https://www.stayed.cn/item/16275
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我