thinkphp框架page类与bootstrap分页(美化)
发布时间 - 2026-01-11 02:02:42 点击率:次bootstrap分样式使用方法这里写链接内容
<nav aria-label="Page navigation">
<ul class="pagination">
<li>
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
<li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >1</a></li>
<li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >2</a></li>
<li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >3</a></li>
<li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >4</a></li>
<li><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >5</a></li>
<li>
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</ul>
</nav>
1.找到Thinkphp中的Page.class.php,然后使用下面的文件内容完全替换
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Think;
class Page{
public $firstRow; // 起始行数
public $listRows; // 列表每页显示行数
public $parameter; // 分页跳转时要带的参数
public $totalRows; // 总行数
public $totalPages; // 分页总页面数
public $rollPage = 11;// 分页栏每页显示的页数
public $lastSuffix = true; // 最后一页是否显示总页数
private $p = 'p'; //分页参数名
private $url = ''; //当前链接URL
private $nowPage = 1;
// 分页显示定制
private $config = array(
'header' => '<li><span>共 %TOTAL_ROW% 条记录<span class="sr-only"></span></span></li>',
'prev' => '<<',
'next' => '>>',
'first' => '1...',
'last' => '...%TOTAL_PAGE%',
'theme' => '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%',
);
/**
* 架构函数
* @param array $totalRows 总的记录数
* @param array $listRows 每页显示记录数
* @param array $parameter 分页跳转的参数
*/
public function __construct($totalRows, $listRows=20, $parameter = array()) {
C('VAR_PAGE') && $this->p = C('VAR_PAGE'); //设置分页参数名称
/* 基础设置 */
$this->totalRows = $totalRows; //设置总记录数
$this->listRows = $listRows; //设置每页显示行数
$this->parameter = empty($parameter) ? $_GET : $parameter;
$this->nowPage = empty($_GET[$this->p]) ? 1 : intval($_GET[$this->p]);
$this->nowPage = $this->nowPage>0 ? $this->nowPage : 1;
$this->firstRow = $this->listRows * ($this->nowPage - 1);
}
/**
* 定制分页链接设置
* @param string $name 设置名称
* @param string $value 设置值
*/
public function setConfig($name,$value) {
if(isset($this->config[$name])) {
$this->config[$name] = $value;
}
}
/**
* 生成链接URL
* @param integer $page 页码
* @return string
*/
private function url($page){
return str_replace(urlencode('[PAGE]'), $page, $this->url);
}
/**
* 组装分页链接
* @return string
*/
public function show() {
if(0 == $this->totalRows) return '';
/* 生成URL */
$this->parameter[$this->p] = '[PAGE]';
$this->url = U(ACTION_NAME, $this->parameter);
/* 计算分页信息 */
$this->totalPages = ceil($this->totalRows / $this->listRows); //总页数
if(!empty($this->totalPages) && $this->nowPage > $this->totalPages) {
$this->nowPage = $this->totalPages;
}
/* 计算分页零时变量 */
$now_cool_page = $this->rollPage/2;
$now_cool_page_ceil = ceil($now_cool_page);
$this->lastSuffix && $this->config['last'] = $this->totalPages;
//上一页
$up_row = $this->nowPage - 1;
$up_page = $up_row > 0 ? '<li><a class="prev" href="' . $this->url($up_row) . '" rel="external nofollow" >' . $this->config['prev'] . '</a></li>' : '';
//下一页
$down_row = $this->nowPage + 1;
$down_page = ($down_row <= $this->totalPages) ? '<li><a class="next" href="' . $this->url($down_row) . '" rel="external nofollow" >' . $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) . '" rel="external nofollow" >' . $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) . '" rel="external nofollow" >' . $this->config['last'] . '</a></li>';
}
//数字连接
$link_page = "";
for($i = 1; $i <= $this->rollPage; $i++){
if(($this->nowPage - $now_cool_page) <= 0 ){
$page = $i;
}elseif(($this->nowPage + $now_cool_page - 1) >= $this->totalPages){
$page = $this->totalPages - $this->rollPage + $i;
}else{
$page = $this->nowPage - $now_cool_page_ceil + $i;
}
if($page > 0 && $page != $this->nowPage){
if($page <= $this->totalPages){
$link_page .= '<li><a class="num" href="' . $this->url($page) . '" rel="external nofollow" >' . $page . '</a></li>';
}else{
break;
}
}else{
if($page > 0 && $this->totalPages != 1){
$link_page .= '<li class="active "><span>'.$page.'<span class="sr-only"></span></span></li>';
}
}
}
//替换分页内容
$page_str = str_replace(
array('%HEADER%', '%NOW_PAGE%', '%UP_PAGE%', '%DOWN_PAGE%', '%FIRST%', '%LINK_PAGE%', '%END%', '%TOTAL_ROW%', '%TOTAL_PAGE%'),
array($this->config['header'], $this->nowPage, $up_page, $down_page, $the_first, $link_page, $the_end, $this->totalRows, $this->totalPages),
$this->config['theme']);
return "<ul class='pagination'>{$page_str}</ul>";
}
}
2.相关控制器代码
//所有新闻
public function all_news(){
$Article=M("Article");
$where['article_type']=1;
//查询满足要求的总的记录数
$count=$Article->where($where)->count();
//实例化分页类传入总记录数和煤业显示的记录数
$Page=new \Think\Page($count,1);
//分页显示输出
$show=$Page->show();
// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
$news=$Article->where($where)->order('pub_time')->field('id,title,institution_type,author_name,pub_time')->limit($Page->firstRow.','.$Page->listRows)->select();
//赋值数据集
$this->assign('news',$news);
//赋值分页输出
$this->assign('page',$show);
$this->display();
}
3.html中只需要
<div class="panel-body center">
{$page}
以上所述是小编给大家介绍的thinkphp框架page类与bootstrap分页(美化),希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
# thinkphp
# page类
# bootstrap分页
# ThinkPHP3.2.3实现分页的方法详解
# thinkPHP3.2实现分页自定义样式的方法
# Thinkphp3.2.3分页使用实例解析
# thinkphp3.2.3 分页代码分享
# thinkPHP3.2.3结合Laypage实现的分页功能示例
# thinkPHP5框架实现分页查询功能的方法示例
# thinkPHP5框架实现基于ajax的分页功能示例
# thinkPHP5框架分页样式类完整示例
# ThinkPHP3.2框架自带分页功能实现方法示例
# 分页
# 每页
# 行数
# 跳转
# 小编
# 下一页
# 上一页
# 零时
# 给大家
# 只需要
# 时要
# 第一页
# 所述
# 要使
# 给我留言
# 有任何
# 数据查询
# zuojiazi
# Author
# qq
相关栏目:
【
网站优化151355 】
【
网络推广146373 】
【
网络技术251813 】
【
AI营销90571 】
相关推荐:
Laravel Session怎么存储_Laravel Session驱动配置详解
mc皮肤壁纸制作器,苹果平板怎么设置自己想要的壁纸我的世界?
Laravel如何处理跨站请求伪造(CSRF)保护_Laravel表单安全机制与令牌校验
音乐网站服务器如何优化API响应速度?
如何在服务器上三步完成建站并提升流量?
php485函数参数是什么意思_php485各参数详细说明【介绍】
Python自然语言搜索引擎项目教程_倒排索引查询优化案例
如何快速生成凡客建站的专业级图册?
网站制作壁纸教程视频,电脑壁纸网站?
佐糖AI抠图怎样调整抠图精度_佐糖AI精度调整与放大细化操作【攻略】
浏览器如何快速切换搜索引擎_在地址栏使用不同搜索引擎【搜索】
Laravel如何处理JSON字段的查询和更新_Laravel JSON列操作与查询技巧
使用spring连接及操作mongodb3.0实例
MySQL查询结果复制到新表的方法(更新、插入)
如何制作公司的网站链接,公司想做一个网站,一般需要花多少钱?
laravel怎么配置Redis作为缓存驱动_laravel Redis缓存配置教程
如何在沈阳梯子盘古建站优化SEO排名与功能模块?
香港服务器租用费用高吗?如何避免常见误区?
Laravel如何实现API版本控制_Laravel版本化API设计方案
Laravel 419 page expired怎么解决_Laravel CSRF令牌过期处理
详解Nginx + Tomcat 反向代理 负载均衡 集群 部署指南
Laravel怎么使用artisan命令缓存配置和视图
智能起名网站制作软件有哪些,制作logo的软件?
如何在阿里云完成域名注册与建站?
如何快速重置建站主机并恢复默认配置?
javascript读取文本节点方法小结
如何在香港服务器上快速搭建免备案网站?
Laravel怎么导出Excel文件_Laravel Excel插件使用教程
公司门户网站制作流程,华为官网怎么做?
Laravel Vite是做什么的_Laravel前端资源打包工具Vite配置与使用
如何用花生壳三步快速搭建专属网站?
ai格式如何转html_将AI设计稿转换为HTML页面流程【页面】
高防服务器:AI智能防御DDoS攻击与数据安全保障
如何在阿里云虚拟服务器快速搭建网站?
如何快速生成橙子建站落地页链接?
中山网站制作网页,中山新生登记系统登记流程?
网站制作软件免费下载安装,有哪些免费下载的软件网站?
Laravel如何与Vue.js集成_Laravel + Vue前后端分离项目搭建指南
Laravel策略(Policy)如何控制权限_Laravel Gates与Policies实现用户授权
如何用PHP工具快速搭建高效网站?
手机网站制作与建设方案,手机网站如何建设?
简历没回改:利用AI润色让你的文字更专业
如何基于PHP生成高效IDC网络公司建站源码?
Laravel Blade模板引擎语法_Laravel Blade布局继承用法
网站制作软件有哪些,制图软件有哪些?
Laravel怎么使用Markdown渲染文档_Laravel将Markdown内容转HTML页面展示【实战】
Laravel项目怎么部署到Linux_Laravel Nginx配置详解
Laravel中的Facade(门面)到底是什么原理
Laravel怎么实现API接口鉴权_Laravel Sanctum令牌生成与请求验证【教程】
Android Socket接口实现即时通讯实例代码

