thinkphp分頁(yè)實(shí)現(xiàn)效果
對(duì)于thinkphp分頁(yè)的實(shí)現(xiàn)效果,一共分為兩種一種是一種調(diào)用公共函數(shù)中的函數(shù)方法,而另一種是模型中書寫分頁(yè)的方法,下面就給需要的朋友來(lái)整理一下。
一、分頁(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è)文檔可以專門放置一些通用的方法,在哪里都可以調(diào)用(如:Controller文件,View文件等)。
二、調(diào)用分頁(yè)方法
$m=M('products');
$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)單的。
.pagination ul {
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}
相關(guān)文章
PHP魔術(shù)方法以及關(guān)于獨(dú)立實(shí)例與相連實(shí)例的全面講解
下面小編就為大家?guī)?lái)一篇PHP魔術(shù)方法以及關(guān)于獨(dú)立實(shí)例與相連實(shí)例的全面講解。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-10-10
實(shí)現(xiàn)PHP框架系列文章(6)mysql數(shù)據(jù)庫(kù)方法
這篇文章主要介紹了實(shí)現(xiàn)PHP框架系列文章(6)mysql數(shù)據(jù)庫(kù)方法的相關(guān)資料,需要的朋友可以參考下2016-03-03
php實(shí)現(xiàn)圖形顯示Ip地址的代碼及注釋
這篇文章主要介紹了php實(shí)現(xiàn)圖形顯示Ip地址,有需要的朋友可以參考一下2014-01-01
Ubuntu VPS中wordpress網(wǎng)站打開(kāi)時(shí)提示”建立數(shù)據(jù)庫(kù)連接錯(cuò)誤”的解決辦法
這篇文章給大家介紹的是在Ubuntu VPS中wordpress網(wǎng)站打開(kāi)時(shí)提示”建立數(shù)據(jù)庫(kù)連接錯(cuò)誤”的解決辦法,相信"建立數(shù)據(jù)庫(kù)連接錯(cuò)誤"大家并不陌生,最近我在做一個(gè)項(xiàng)目的時(shí)候就又遇到了這個(gè)問(wèn)題,現(xiàn)在將我解決的步驟分享給大家,希望對(duì)同樣遇到這個(gè)問(wèn)題的朋友們能有所幫助。2016-11-11
PHP中用Trait封裝單例模式的實(shí)現(xiàn)
這篇文章主要介紹了PHP中用Trait封裝單例模式的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
php實(shí)現(xiàn)微信支付之現(xiàn)金紅包
這篇文章主要為大家詳細(xì)介紹了php實(shí)現(xiàn)微信支付之現(xiàn)金紅包,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05
Zend Framework教程之請(qǐng)求對(duì)象的封裝Zend_Controller_Request實(shí)例詳解
這篇文章主要介紹了Zend Framework教程之請(qǐng)求對(duì)象的封裝Zend_Controller_Request用法,結(jié)合實(shí)例形式詳細(xì)分析了請(qǐng)求對(duì)象封裝的原理,使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-03-03
Symfony2使用第三方庫(kù)Upload制作圖片上傳實(shí)例詳解
這篇文章主要介紹了Symfony2使用第三方庫(kù)Upload制作圖片上傳的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Symfony2使用第三方庫(kù)Upload的具體步驟與相關(guān)使用技巧,需要的朋友可以參考下2016-02-02

