這篇文章主要介紹了關於thinkphp3.2.3分頁完整執行個體,有著一定的參考價值,現在分享給大家,有需要的朋友可以參考一下
Common公用函數:
/** * TODO 基礎分頁的相同代碼封裝,使前台的代碼更少 * @param $count 要分頁的總記錄數 * @param int $pagesize 每頁查詢條數 * @return \Think\Page */ function getPage($count, $pagesize = 10) { $p = new Think\Page($count, $pagesize); $p->setConfig('header', '<li class="rows">共<b>%TOTAL_ROW%</b>條記錄 第<b>%NOW_PAGE%</b>頁/共<b>%TOTAL_PAGE%</b>頁</li>'); $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->lastSuffix = false;//最後一頁不顯示為總頁數 return $p; }
Controller控制器:
$count= M('admin_column_class')->count(); //查詢滿足條件的總記錄數 $p = getPage($count,10); $show = $p->show(); // 分頁顯示輸出 $row= M('admin_column_class')->order('id')->limit($p->firstRow.','.$p->listRows)->select(); $this->assign('row',$row); $this->assign('count',$count); $this->assign('show',$show); $this->display();
View視圖:
HTML
<p class="pages"> {$show}</p>
CSS
/*To change this license header, choose License Headers in Project Properties.To change this template file, choose Tools | Templatesand open the template in the editor.*//* Created on : 2017-11-1, 11:04:50 Author : Yoko(wanlala615@qq.com)*/ .pages a, .pages span { display: inline-block; padding: 2px 5px; margin: 0 1px; border: 1px solid #f0f0f0; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; } .pages a, .pages li { display: inline-block; list-style: none; text-decoration: none; color: #58A0D3; } .pages a.first, .pages a.prev, .pages a.next, .pages a.end { margin: 0; } .pages a:hover { border-color: #50A8E6; } .pages span.current { background: #50A8E6; color: #FFF; font-weight: 700; border-color: #50A8E6; }
: