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