ThinkPHP 3.2 數(shù)據(jù)分頁(yè)代碼分享
TP3.2框架手冊(cè),有一個(gè)數(shù)據(jù)分頁(yè),不過(guò)每次都要寫太多的代碼,還有中文設(shè)置等有些麻煩,做為程序開(kāi)發(fā)者,有必要整理下:
O、先看效果圖

一、分頁(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}
- tp5框架內(nèi)使用tp3.2分頁(yè)的方法分析
- tp5框架無(wú)刷新分頁(yè)實(shí)現(xiàn)方法分析
- TP5框架實(shí)現(xiàn)自定義分頁(yè)樣式的方法示例
- ThinkPHP分頁(yè)類使用詳解
- Thinkphp搜索時(shí)首頁(yè)分頁(yè)和搜索頁(yè)保持條件分頁(yè)的方法
- thinkPHP5分頁(yè)功能實(shí)現(xiàn)方法分析
- ThinkPHP3.2.3實(shí)現(xiàn)分頁(yè)的方法詳解
- 在Thinkphp中使用ajax實(shí)現(xiàn)無(wú)刷新分頁(yè)的方法
- Thinkphp和Bootstrap結(jié)合打造個(gè)性的分頁(yè)樣式(推薦)
- thinkPHP5框架分頁(yè)樣式類完整示例
- thinkPHP3.2實(shí)現(xiàn)分頁(yè)自定義樣式的方法
- TP3.2框架分頁(yè)相關(guān)實(shí)現(xiàn)方法分析
相關(guān)文章
Laravel 實(shí)現(xiàn)在Blade模版中使用全局變量代替路徑的例子
今天小編就為大家分享一篇Laravel 實(shí)現(xiàn)在Blade模版中使用全局變量代替路徑的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-10-10
Zend Framework實(shí)現(xiàn)Zend_View集成Smarty模板系統(tǒng)的方法
這篇文章主要介紹了Zend Framework實(shí)現(xiàn)Zend_View集成Smarty模板系統(tǒng)的方法,詳細(xì)分析了視圖組件Zend_View使用接口Zend_View_Interface繼承Smarty的原理與實(shí)現(xiàn)技巧,需要的朋友可以參考下2016-03-03
php array_keys 返回?cái)?shù)組的鍵名
php中array_keys函數(shù)用于返回包含數(shù)組中所有鍵名的一個(gè)新數(shù)組。本文章向大家詳細(xì)介紹PHP array_keys函數(shù)使用方法。需要的碼農(nóng)可以參考一下2016-10-10
Thinkphp5+Redis實(shí)現(xiàn)商品秒殺代碼實(shí)例講解
這篇文章主要介紹了Thinkphp5+Redis實(shí)現(xiàn)商品秒殺代碼實(shí)例講解,代碼和步驟講解的很清楚,有需要的同學(xué)可以借鑒參考下2020-12-12

