ThinkPHP分頁(yè)實(shí)例
本文實(shí)例講述了ThinkPHP分頁(yè)的實(shí)現(xiàn)方法,分享給大家供大家參考。具體方法如下:
在TP3.2框架手冊(cè)中有一個(gè)數(shù)據(jù)分頁(yè),不過(guò)每次都要寫(xiě)太多的代碼,還有中文設(shè)置等有些麻煩,做為程序開(kāi)發(fā)者,有必要整理下:
實(shí)例運(yùn)行效果如下圖所示:

一、分頁(yè)方法:
* TODO 基礎(chǔ)分頁(yè)的相同代碼封裝,使前臺(tái)的代碼更少
* @param $m 模型,引用傳遞
* @param $where 查詢條件
* @param int $pagesize 每頁(yè)查詢條數(shù)
* @return \Think\Page
*/
function getpage(&$m,$where,$pagesize=10){
$m1=clone $m;//淺復(fù)制一個(gè)模型
$count = $m->where($where)->count();//連慣操作后會(huì)對(duì)join等操作進(jìn)行重置
$m=$m1;//為保持在為定的連慣操作,淺復(fù)制一個(gè)模型
$p=new Think\Page($count,$pagesize);
$p->lastSuffix=false;
$p->setConfig('header','<li class="rows">共<b>%TOTAL_ROW%</b>條記錄 每頁(yè)<b>%LIST_ROW%</b>條 第<b>%NOW_PAGE%</b>頁(yè)/共<b>%TOTAL_PAGE%</b>頁(yè)</li>');
$p->setConfig('prev','上一頁(yè)');
$p->setConfig('next','下一頁(yè)');
$p->setConfig('last','末頁(yè)');
$p->setConfig('first','首頁(yè)');
$p->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$p->parameter=I('get.');
$m->limit($p->firstRow,$p->listRows);
return $p;
}
getpage方法可以放在TP框架的 Application/Common/Common/function.php,這個(gè)文檔可以專(zhuān)門(mén)放置一些通用的方法,在哪里都可以調(diào)用(如:Controller文件,View文件等)。
二、調(diào)用分頁(yè)方法
$p=getpage($m,$where,10);
$list=$m->field(true)->where($where)->order('id desc')->select();
$this->list=$list;
$this->page=$p->show();
再是View代碼
<div class="pagination">
{$page}
</div>
三、最后就是分頁(yè)的樣式了,這個(gè)有些亂,因后臺(tái)框架網(wǎng)上下載的,樣式還沒(méi)來(lái)的及整理,這個(gè)樣式也可以自己實(shí)現(xiàn),簡(jiǎn)單的。
display: inline-block;
margin-bottom: 0;
margin-left: 0;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.05);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,0.05);
box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.pagination ul li {
display: inline;
}
.pagination ul li.rows {
line-height: 30px;
padding-left: 5px;
}
.pagination ul li.rows b{color: #f00}
.pagination ul li a, .pagination ul li span {
float: left;
padding: 4px 12px;
line-height: 20px;
text-decoration: none;
background-color: #fff;
background: url('../images/bottom_bg.png') 0px 0px;
border: 1px solid #d3dbde;
/*border-left-width: 0;*/
margin-left: 2px;
color: #08c;
}
.pagination ul li a:hover{
color: red;
background: #0088cc;
}
.pagination ul li.first-child a, .pagination ul li.first-child span {
border-left-width: 1px;
-webkit-border-bottom-left-radius: 3px;
border-bottom-left-radius: 3px;
-webkit-border-top-left-radius: 3px;
border-top-left-radius: 3px;
-moz-border-radius-bottomleft: 3px;
-moz-border-radius-topleft: 3px;
}
.pagination ul .disabled span, .pagination ul .disabled a, .pagination ul .disabled a:hover {
color: #999;
cursor: default;
background-color: transparent;
}
.pagination ul .active a, .pagination ul .active span {
color: #999;
cursor: default;
}
.pagination ul li a:hover, .pagination ul .active a, .pagination ul .active span {
background-color: #f0c040;
}
.pagination ul li.last-child a, .pagination ul li.last-child span {
-webkit-border-top-right-radius: 3px;
border-top-right-radius: 3px;
-webkit-border-bottom-right-radius: 3px;
border-bottom-right-radius: 3px;
-moz-border-radius-topright: 3px;
-moz-border-radius-bottomright: 3px;
}
.pagination ul li.current a{color: #f00 ;font-weight: bold; background: #ddd}
希望本文所述對(duì)大家的ThinkPHP框架程序開(kāi)發(fā)有所幫助。
- 在Thinkphp中使用ajax實(shí)現(xiàn)無(wú)刷新分頁(yè)的方法
- ThinkPHP使用心得分享-分頁(yè)類(lèi)Page的用法
- ThinkPHP分頁(yè)類(lèi)使用詳解
- Thinkphp搜索時(shí)首頁(yè)分頁(yè)和搜索頁(yè)保持條件分頁(yè)的方法
- thinkPHP5分頁(yè)功能實(shí)現(xiàn)方法分析
- ThinkPHP3.2.3實(shí)現(xiàn)分頁(yè)的方法詳解
- thinkPHP5框架實(shí)現(xiàn)分頁(yè)查詢功能的方法示例
- thinkPHP5框架分頁(yè)樣式類(lèi)完整示例
- thinkPHP5框架實(shí)現(xiàn)基于ajax的分頁(yè)功能示例
- thinkPHP5使用laypage分頁(yè)插件實(shí)現(xiàn)列表分頁(yè)功能
- tp5框架無(wú)刷新分頁(yè)實(shí)現(xiàn)方法分析
相關(guān)文章
windows安裝composer并更換國(guó)內(nèi)鏡像的過(guò)程詳解
這篇文章主要給大家介紹了windows安裝composer并更換國(guó)內(nèi)鏡像的過(guò)程詳解,文中有詳細(xì)的流程介紹,通過(guò)圖文結(jié)合講解的非常詳細(xì),需要的朋友可以參考下2023-11-11
PHP中使用CURL發(fā)送get/post請(qǐng)求上傳圖片批處理功能
這篇文章主要介紹了PHP中使用CURL發(fā)送get/post請(qǐng)求上傳圖片批處理 功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-10-10
淺談mysql_query()函數(shù)的返回值問(wèn)題
下面小編就為大家?guī)?lái)一篇淺談mysql_query()函數(shù)的返回值問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-09-09
Codeigniter里的無(wú)刷新上傳的實(shí)現(xiàn)代碼
這篇文章主要介紹了Codeigniter里的無(wú)刷新上傳的實(shí)現(xiàn)代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
Ubuntu中啟用php的mail()函數(shù)并解決發(fā)送郵件速度慢問(wèn)題
本文主要給大家介紹的是在Ubuntu下安裝sendmail的方法,以及啟用sendmail之后,php發(fā)送郵件緩慢的原因及解決方法,有需要的小伙伴可以參考下。2015-03-03
Laravel使用消息隊(duì)列需要注意的一些問(wèn)題
這篇文章主要給大家介紹了關(guān)于Laravel使用消息隊(duì)列需要注意的一些問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起看看吧。2017-12-12
Aliyun Linux 編譯安裝 php7.3 tengine2.3.2 mysql8.0 redis5的過(guò)程詳解
這篇文章主要介紹了Aliyun Linux 編譯安裝 php7.3 tengine2.3.2 mysql8.0 redis5,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10

