您的位置:首页 > Web前端 > BootStrap

thinkphp整合bootstrap分页

2016-02-02 16:56 483 查看
编辑Thinkphp/library/page.class.php文件,在分页的的html标签明,外包一个li元素,如

//上一页

$up_row  = $this->nowPage - 1;

$up_page = $up_row > 0 ? '<a class="prev" aria-label="Previous" href="' . $this->url($up_row) . '">' . $this->config['prev'] . '</a>' : '';

修改为

$up_row  = $this->nowPage - 1;

$up_page = $up_row > 0 ? '<li><a class="prev" aria-label="Previous" href="' . $this->url($up_row) . '">' . $this->config['prev'] . '</a></li>' : '';

//下一页

$down_row  = $this->nowPage + 1;

$down_page = ($down_row <= $this->totalPages) ? '<li><a class="next" aria-label="Next" href="' . $this->url($down_row) . '">' . $this->config['next'] . '</a></li>' : '';

//第一页

$the_first = '';

if($this->totalPages > $this->rollPage && ($this->nowPage - $now_cool_page) >= 1){

$the_first = '<li><a class="first" href="' . $this->url(1) . '">' . $this->config['first'] . '</a></li>';

}

//最后一页

$the_end = '';

if($this->totalPages > $this->rollPage && ($this->nowPage + $now_cool_page) < $this->totalPages){

$the_end = '<li><a class="end" href="' . $this->url($this->totalPages) . '">' . $this->config['last'] . '</a></li>';

}

//中间连接页

$link_page .= '<li><a class="num" href="' . $this->url($page) . '">' . $page . '</a></li>';

//当前面页

$link_page .= '<li class="active"><span class="current">' . $page . '</span></li>';

//最后修改return,去掉div标签,变成

return "{$page_str}";


为了page.class.php能适应更多的样式,所以page.class.php里面的html标签只外套一个li元素,当你不想用bootstrap,page.class.php文件不用再更改

$User = M('t_msg'); // 实例化User对象
$count= $User->count();// 查询满足要求的总记录数
$Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
//$Page->setConfig()设置样式
$Page->setConfig('prev',  '<span aria-hidden="true">上一页</span>');//上一页
$Page->setConfig('next',  '<span aria-hidden="true">下一页</span>');//下一页
$Page->setConfig('first', '<span aria-hidden="true">首页</span>');//第一页
$Page->setConfig('last',  '<span aria-hidden="true">尾页</span>');//最后一页
//$Page->setConfig('theme','');设置你想显示的按钮,%XXXX%含义参照图示
$Page->setConfig ( 'theme', '<li><a>当前%NOW_PAGE%/%TOTAL_PAGE%</a></li>  %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%' );
$show= $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
// $userList = $User->where('1')->order('comnum desc')->limit($Page->firstRow.','.$Page->listRows)->select();
$sql='select a.id ,a.content ,a.title,a.post_date,
a.comnum,b.username
4000
from t_msg as a, userd as b where user_id=
b.id  order by comnum desc limit '.$Page->firstRow.','.$Page->listRows;
$Dao  = M();
$userList = $Dao->query($sql);

// print_r($userList);
$this->assign('userList',$userList);// 赋值数据集
$this->assign('page',$show);// 赋值分页输出
$this->display('bbs');//显示登录页面

最后,是在模板调用分页,

模板引入bootstrap.min.css

{$page}表示引用分页,把 {$page}放到<ul class="pagination"></ul>内

<ul class="pagination">

{$page}

</ul>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  bootstrap thinkphp 分页