本篇文章給大家分享的是有關怎么在thinkphp項目中實現一個分頁顯示功能,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
IndexController.class.php代碼如下
public function index(){
$m=M('Info');
$count = $m->where($where)->count();
$pageCount = 10;//每頁顯示數量
$page = new \Think\Page($count , $pageCount);
$page->parameter = $row; //此處的row是數組,為了傳遞查詢條件
$page->setConfig('header','條留言');
$page->setConfig('first','首頁');
$page->setConfig('prev','上一頁');
$page->setConfig('next','下一頁');
$page->setConfig('last','尾頁');
$page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%<div id="pageTips">第 '.I('p',1).' 頁/共 %TOTAL_PAGE% 頁 ( '.$pageCount.' 條/頁 共 %TOTAL_ROW% 條信息)</div>');
$show = $page->show();
$list = $m->where($where)->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
$this->assign('infoList',$list);
$this->assign('show',$show);
$this->display();
}index.html代碼如下
<table class="table table-hover table-striped" id="table">
<tr class="danger">
<th>類別</th>
<th>信息標題</th>
<th>物品類型</th>
<th>遺失/拾物時間</th>
<th>遺失/拾物地點</th>
<th >發布時間</th>
</tr>
<foreach name="infoList" item='vo'>
<tr >
<td>{$vo.info_type}</td>
<td>{$vo.info_title}</td>
<td>{$vo.thing_type}</td>
<td>{$vo.info_time}</td>
<td>{$vo.info_place}</td>
<td>{$vo.create_time}</td>
</tr>
</foreach>
</table>
<div class="page">
<ul>
{$show}
</ul>
</div>css代碼如下
/* start 分頁樣式 */
.page{
overflow:hidden;
margin:50px 0 50px 100px;;
}
.page ul a,.page ul span{
float:left;
display:inline-block;
padding: 0 17px;
height:40px;
width:auto;
border:1px solid #DDDDDD;
border-radius: 4px;
background:#fff;
text-align:center;
line-height:40px;
margin-right:10px;
font-family: "microsoft yahei" simhei sans-serif;
color:#7d7d7d;
}
.page ul a:hover{
background:#337AB7;
color:#fff;
text-decoration:none;
}
.page ul span.current{
background: #337AB7;
color:#fff;
}
.page ul a:first,.page ul a:last{
float:left;
display:inline-block;
width:40px;
height:40px;
border-radius:50%;
background:rgb(215, 215, 217);
text-align:center;
line-height:40px;
margin-right:10px;
font-family: "microsoft yahei" simhei sans-serif;
}
#pageTips {
float:right;
}
/* end 分頁樣式 */以上就是怎么在thinkphp項目中實現一個分頁顯示功能,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。