通过 limit,page分页
控制器:
$rel = $member->limit(5)->page($_GET['p'])->select();
$mecount = $member->select();
$Pages = new \Think\Page(count($mecount),5);// 实例化分页类 传入总记录数和每页显示的记录数
$Pages->setConfig('header','<span class="rows">共 %TOTAL_ROW% 位会员</span>');
$Pages->setConfig('prev','上一页');
$Pages->setConfig('next','下一页');
$Pages->setConfig('first','首页');//第一页
$Pages->setConfig('last','末页');//最后一页
$show = $Pages->show();// 分页显示输出
$this->assign('page', $show);
Page.class.php
将第 33行:
'theme' => '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%',
改为:
'theme' => '%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%',
// %HEADER% 总条数
第103行:
//第一页
if($this->totalPages > $this->rollPage && ($this->nowPage - $now_cool_page) >= 1){
$the_first = '<a class="first" href="' . $this->url(1) . '">' . $this->config['first'] . '</a>';
}
改为:
if(!empty($down_page) || !empty($up_page)){
$the_first = '<a class="first" href="' . $this->url(1) . '">' . $this->config['first'] . '</a>';
}
//显示 首页
第108行:
//最后一页
if($this->totalPages > $this->rollPage && ($this->nowPage + $now_cool_page) < $this->totalPages){
$the_end = '<a class="end" href="' . $this->url($this->totalPages) . '">' . $this->config['last'] . '</a>';
}
改为:
if(!empty($down_page) || !empty($up_page)){
$the_end = '<a class="end" href="' . $this->url($this->totalPages) . '">' . $this->config['last'] . '</a>';
}
第92行:
$this->lastSuffix && $this->config['last'] = $this->totalPages;
改为:
$this->lastSuffix = $this->totalPages;
//显示 末页
模板:
<div class='page'>{$page}</div>
css样式:
.page{ text-align:center; margin-top:20px; height:30px;}
.page a,.page span{ margin-left:10px;}
.page .num{width:50px;border:1px solid #CCC;margin-left:5px;text-decoration:none; padding:2px 15px;}
.current{background:#34cdf6;width:50px;border:1px solid #CCC;margin-left:10px;color:#036cb4;padding:2px 15px;}
Think PHP 3.2 分页
最新推荐文章于 2024-07-14 18:57:12 发布