Thinkphp5之Bootstrap自定义BootstrapDetailed分页插件的实现
首先,在此目录建立一个newcrm\thinkphp\library\think\paginator\driver\BootstrapDetailed.php文件,代码如下:
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: zhangyajun <448901948@qq.com>
// +---------------------------------------------------------------------- namespace think\paginator\driver; use think\Paginator; class BootstrapDetailed extends Paginator
{ /**
* 上一页按钮
* @param string $text
* @return string
*/
protected function getPreviousButton($text = "上一页")
{ if ($this->currentPage() <= 1) {
return $this->getDisabledTextWrapper($text);
} $url = $this->url(
$this->currentPage() - 1
); return $this->getPageLinkWrapper($url, $text);
} //总数标签
protected function totalshow()
{ $totalhtml="<li class=\"disabled\"><span>共".$this->total."条记录  第".$this->currentPage()."页/共".$this->lastPage()."页</span></li>";
return $totalhtml; } //尾页标签 protected function showlastpage($text = '尾页')
{ if($this->currentPage()==$this->lastPage())
{
return $this->getDisabledTextWrapper($text); } $url = $this->url($this->lastPage());
return $this->getPageLinkWrapper($url, $text);
} //首页标签 protected function showfirstpage($text = '首页')
{ if($this->currentPage()==1)
{
return $this->getDisabledTextWrapper($text); } $url = $this->url(1);
return $this->getPageLinkWrapper($url, $text);
}
//后五页
protected function afivepage($text = '后五页')
{ if($this->lastPage()<$this->currentPage()+5)
{
return $this->getDisabledTextWrapper($text); }
$url = $this->url($this->currentPage()+5); return $this->getPageLinkWrapper($url, $text);
} //前五页
protected function bfivepage($text = '前五页')
{ if($this->currentPage()<5)
{
return $this->getDisabledTextWrapper($text); }
$url = $this->url($this->currentPage()-5); return $this->getPageLinkWrapper($url, $text);
} /**
* 下一页按钮
* @param string $text
* @return string
*/
protected function getNextButton($text = '下一页')
{
if (!$this->hasMore) {
return $this->getDisabledTextWrapper($text);
} $url = $this->url($this->currentPage() + 1); return $this->getPageLinkWrapper($url, $text);
} //跳转到哪页
protected function gopage()
{ return $gotohtml="<li><form action='' method='get' ><span><input type='text' name='page'> <input type='submit' value='确定'> </span></form></li>";
// return $totalhtml;; } /**
* 页码按钮
* @return string
*/
protected function getLinks()
{
if ($this->simple)
return ''; $block = [
'first' => null,
'slider' => null,
'last' => null
]; $side = 2;
$window = $side * 2; if ($this->lastPage < $window +1) {
$block['slider'] = $this->getUrlRange(1, $this->lastPage); } elseif ($this->currentPage <= $window-1) { $block['slider'] = $this->getUrlRange(1, $window + 1);
} elseif ($this->currentPage > ($this->lastPage - $window+1)) {
$block['slider'] = $this->getUrlRange($this->lastPage - ($window), $this->lastPage); } else { $block['slider'] = $this->getUrlRange($this->currentPage - $side, $this->currentPage + $side);
} $html = ''; if (is_array($block['first'])) {
$html .= $this->getUrlLinks($block['first']);
} if (is_array($block['slider'])) { $html .= $this->getUrlLinks($block['slider']);
} if (is_array($block['last'])) {
$html .= $this->getUrlLinks($block['last']);
} return $html;
} /**
* 渲染分页html
* @return mixed
*/
public function render()
{
if ($this->hasPages()) {
if ($this->simple) {
return sprintf(
'<ul class="pager">%s %s %s</ul>', $this->getPreviousButton(),
$this->getNextButton()
);
} else {
return sprintf(
'<ul class="pagination"> %s %s %s %s %s %s %s %s </ul>',
//显示数量页码信息
$this->totalshow(),
//第一页
$this->showfirstpage(),
//上一页
$this->getPreviousButton(),
//前五页
$this->bfivepage(),
//页码
$this->getLinks(),
//后五页
$this->afivepage(),
//下一页
$this->getNextButton(),
//最后一页
$this->showlastpage()
//最后再加个参数 %s 可以显示跳转到哪页
// $this->gopage() );
}
}
} /**
* 生成一个可点击的按钮
*
* @param string $url
* @param int $page
* @return string
*/
protected function getAvailablePageWrapper($url, $page)
{
return '<li><a href="' . htmlentities($url) . '">' . $page . '</a></li>';
} /**
* 生成一个禁用的按钮
*
* @param string $text
* @return string
*/
protected function getDisabledTextWrapper($text)
{
return '<li class="disabled"><span>' . $text . '</span></li>';
} /**
* 生成一个激活的按钮
*
* @param string $text
* @return string
*/
protected function getActivePageWrapper($text)
{
return '<li class="active"><span>' . $text . '</span></li>';
} /**
* 生成省略号按钮
*
* @return string
*/
protected function getDots($text = '...')
{ //$url = $this->url($this->currentPage() + 1); // return $this->getPageLinkWrapper($url, $text);
return $this->getDisabledTextWrapper('...');
} /**
* 批量生成页码按钮.
*
* @param array $urls
* @return string
*/
protected function getUrlLinks(array $urls)
{
$html = ''; foreach ($urls as $page => $url) {
$html .= $this->getPageLinkWrapper($url, $page);
} return $html;
} /**
* 生成普通页码按钮
*
* @param string $url
* @param int $page
* @return string
*/
protected function getPageLinkWrapper($url, $page)
{
if ($page == $this->currentPage()) {
return $this->getActivePageWrapper($page);
} return $this->getAvailablePageWrapper($url, $page);
}
}
其次,在需要调用的控制器类里面写后台方法:如下
public function semList(){
//分页查询方法:
//方法一:自定义BootstrapDetailed实现分页倒叙列表查询
//$semList = SemModel::name('sem')->order('create_time desc')->paginate(6,false,['type' => 'BootstrapDetailed',]);
//方法二:laypage实现分页倒叙列表查询
$nowpage=input('page',1);//获取post传来的页数,如果没有页数时,页数为1
$totalpage=ceil((model('sem')->count())/10);////$totalpage就是计算你要获取的最大页数,ceil 是向前取整,这里是设置为10条数据为1页(注意括号)//这里尽量简写了。
//下面注意加上 这句 limit(($nowpage-1)*10,10),就是数据控制每页显示数据的条数,获取页数后乘以设置的条数,获取该页的10条(自己设置)数据
$semList=model('sem')->order('create_time desc')->limit(($nowpage-1)*10,10)->select();
$count = SemModel::count();
$this->assign("totalpage",$totalpage);
$this->assign('count',$count);
$this->assign('semList',$semList);
return $this->fetch('sem_list');
}
然后,在html页面显示分页代码
<!--显示分页按钮,事先要将bootstrap导入css和js-->
<div style="float: right;margin-right: 20%;">
<div class="row">
<div class="col-lg-12"></div>
<div class="col-lg-12">{$rateList->render()}</div></div>
<div class="col-lg-12"></div>
</div>
最后,引入boostrap的js和css
{load href="__STATIC__/lib/bootstrap/css/bootstrap.min.css"/}
Thinkphp5之Bootstrap自定义BootstrapDetailed分页插件的实现的更多相关文章
- Bootstrap的js分页插件属性介绍
Bootstrap Paginator是一款基于Bootstrap的js分页插件,功能很丰富,个人觉得这款插件已经无可挑剔了.它提供了一系列的参数用来支持用户的定 制,提供了公共的方法可随时获得插件状 ...
- 一款基于Bootstrap的js分页插件bootstrap-paginator使用实例
Bootstrap Paginator是一款基于Bootstrap的js分页插件,功能很丰富.它提供了一系列的参数用来支持用户的定制,提供了公共的方法可随时获得插件状态的改变,以及事件来监听用户的动作 ...
- springboot多数据源动态切换和自定义mybatis分页插件
1.配置多数据源 增加druid依赖 完整pom文件 数据源配置文件 route.datasource.driver-class-name= com.mysql.jdbc.Driver route.d ...
- jQuery分页插件jBootstrapPage,一个Bootstrap风格的分页插件
一个Bootstrap风格的分页控件,对于喜欢Bootstrap简洁美观和扁平化的同学可以关注jBootstrapPage, 目前jBootstrapPage最新版为V0.1,后续还有更多功能需要完善 ...
- 高仿bootstrap样式的分页插件
链接:https://pan.baidu.com/s/1jKgn2hK 密码:whwl 不知道是自己的第几个分页插件了,以前写一个丢一个,桌面,U盘,移动硬盘.想用的时候找不到,这次传网上来.大家帮忙 ...
- 自定义Jquery分页插件
/** * 功能说明:jPager 分页插件 * 参数说明:pages:[] 分页的控件个数 @id:显示分页的div ID,@showSelectPage: 是否显示当前分页的条目过滤下拉框 * @ ...
- Bootstrap Paginator 分页插件参数介绍及使用
Bootstrap Paginator是一款基于Bootstrap的js分页插件,功能很丰富,个人觉得这款插件已经无可挑剔了.它提供了一系列的参数用来支持用户的定制,提供了公共的方法可随时获得插件状态 ...
- 分页插件 Bootstrap Paginator
Bootstrap Paginator是一款基于Bootstrap的js分页插件,功能很丰富,个人觉得这款插件已经无可挑剔了.它提供了一系列的参数用来支持用户的定制,提供了公共的方法可随时获得插件状态 ...
- Bootstrap Paginator分页插件
Bootstrap Paginator分页插件使用示例 最近做的asp.netMVC项目中需要对数据列表进行分类,这个本来就是基于bootstrap开发的后台,因此也就想着bootstrap是否有分页 ...
随机推荐
- 使用windbg定位内存问题【入门级】
1. 背景 在开发过程中,我们可能遇到应用程序线程占用过大的问题,可以通过windbg命令去定位哪些类型,哪些内存一直占用堆资源,从而查出问题,解决问题. 2. 准备工作 工具: 抓取DUMP文件的工 ...
- [Elementary Mechanics Using Python-02]Feather in tornado
Problem 9.17 Feather in tornado. In this project you will learn to use Newton's laws and the force m ...
- 解决.NET Core Ajax请求后台传送参数过大请求失败问题
解决.NET Core Ajax请求后台传送参数过大请求失败问题 今天在项目上遇到一个坑, 在.Net Core中通过ajax向mvc的controller传递对象时,控制器(controller)的 ...
- 分布式基础理论之CAP 和BASE
前言 本文聊聊 CAP 定理和 BASE 理论. CAP 定理 C:一致性(Consistency) 数据的强一致性.希望分布式系统只读到最新写入的数据 A:可用性(Availability) 分布式 ...
- ijkplayer接入使用
1.ijkplayer简介 ijkplayer是一个基于FFmpeg的轻量级Android/iOS视频播放器.FFmpeg的是全球领先的多媒体框架,能够解码,编码, 转码,复用,解复用,流,过滤器和播 ...
- springboot源码解析-管中窥豹系列之BeanFactoryPostProcessor(十一)
一.前言 Springboot源码解析是一件大工程,逐行逐句的去研究代码,会很枯燥,也不容易坚持下去. 我们不追求大而全,而是试着每次去研究一个小知识点,最终聚沙成塔,这就是我们的springboot ...
- JS逆向-抠代码的第一天【手把手学会抠代码】
首先声明,本人经过无数次摸爬滚打及翻阅各类资料,理论知识极其丰富,但是抠代码怎么都抠不会. 无奈之下,只能承认:这个活,需要熟练度. 本文仅对部分参数进行解析,有需要调用,请自行根据现实情况调整. 第 ...
- Java工程师核心书单推荐
随便打开一个招聘网站,看看对高级Java工程师的技能要求. 抛开其它的经验能力等等,单纯从技术,或者说知识上来讲,可以发现一些共通的地方. Java基础 计算机基础 数据库,SQL/NoSQL 常用开 ...
- Codeforces Round #574 (Div. 2) D2. Submarine in the Rybinsk Sea (hard edition) 【计算贡献】
一.题目 D2. Submarine in the Rybinsk Sea (hard edition) 二.分析 相比于简单版本,它的复杂地方在于对于不同长度,可能对每个点的贡献可能是有差异的. 但 ...
- java mvc 及其缓存
使用Spring框架的好处是什么? - 轻量:Spring 是轻量的,基本的版本大约2MB. - 控制反转:Spring通过控制反转实现了松散耦合,对象们给出它们的依赖,而不是创建或查找依赖的对象们. ...