Mode代码php
/** * TODO 基础分页的相同代码封装,使前台的代码更少 * @param $m 模型,引用传递 * @param $where 查询条件 * @param int $pagesize 每页查询条数 * @return \Think\Page */ public function getpage(&$m, $where, $pagesize = 20) { $m1 = clone $m; //浅复制一个模型 $count = $m->where($where)->count(); //连惯操做后会对join等操做进行重置 $m = $m1; //为保持在为定的连惯操做,浅复制一个模型 $p = new Page($count, $pagesize); $p->lastSuffix = false; $p->setConfig('header', '共[<b>%TOTAL_ROW%</b>]条记录 第[<b>%NOW_PAGE%</b>]页/共[<b>%TOTAL_PAGE%</b>]页'); $p->setConfig('prev', '上一页'); $p->setConfig('next', '下一页'); $p->setConfig('last', '末页'); $p->setConfig('first', '首页'); $p->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); // 分页时候携带的参数 $p->parameter = I('get.'); //dump($p->parameter); $m->limit($p->firstRow, $p->listRows); return $p; }
Controller 调用代码css
public function index() { // 组织where条件 $where = array(); $where['number'] = I('get.number'); $where['type'] = I('get.type'); // 调用查询数据 $m = D('Pay'); $p = $m->getpage($m, $where, 20); $list = $m->field(true)->where($where)->order('itemid desc')->select(); $this->assign('pays', $list); $page = $p->show(); $this->assign('page', $page); $this->assign('p', $where); // 用于搜索框值的回显 $this->display(); }
View html使用html
<div class="pages"> {$page} </div>
CSS样式post
<!--分页样式--> <style> .pages { width: 100%; text-align: center; padding: 20px 0; clear: both; position: absolute; bottom: 0px; } .pages a, .pages .current { font-size: 12px; font-family: Arial; margin: 0 2px; } .pages a, .pages .current { border: 1px solid #5FA623; background: #fff; padding: 2px 6px; text-decoration: none; } .pages .current, .pages a:hover { background: #7AB63F; color: #fff; } </style>
效果图this
备注code
1.form表单使用get提交方式!(post方式正在研究,暂时尚未实现,估计是我配置的问题)orm