\thinkphp\library\think\paginator\driver

添加 Layui.php

<?php

namespace think\paginator\driver;

use think\Paginator;

class Layui 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);

}

/**

* 下一页按钮

* @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);

}

/**

* 页码按钮

* @return string

*/

protected function getLinks()

{

if ($this->simple)

return '';

$block = [

'first' => null,

'slider' => null,

'last' => null

];

$side = 3;

$window = $side * 2;

if ($this->lastPage < $window + 6) {

$block['first'] = $this->getUrlRange(1, $this->lastPage);

} elseif ($this->currentPage <= $window) {

$block['first'] = $this->getUrlRange(1, $window + 2);

$block['last'] = $this->getUrlRange($this->lastPage - 1, $this->lastPage);

} elseif ($this->currentPage > ($this->lastPage - $window)) {

$block['first'] = $this->getUrlRange(1, 2);

$block['last'] = $this->getUrlRange($this->lastPage - ($window + 2), $this->lastPage);

} else {

$block['first'] = $this->getUrlRange(1, 2);

$block['slider'] = $this->getUrlRange($this->currentPage - $side, $this->currentPage + $side);

$block['last'] = $this->getUrlRange($this->lastPage - 1, $this->lastPage);

}

$html = '';

if (is_array($block['first'])) {

$html .= $this->getUrlLinks($block['first']);

}

if (is_array($block['slider'])) {

$html .= $this->getDots();

$html .= $this->getUrlLinks($block['slider']);

}

if (is_array($block['last'])) {

$html .= $this->getDots();

$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</ul>',

$this->getPreviousButton(),

$this->getNextButton()

);

} else {

return sprintf(

'%s %s %s',

$this->getPreviousButton(),

$this->getLinks(),

$this->getNextButton()

);

}

}

}

/**

* 生成一个可点击的按钮

*

* @param string $url

* @param int $page

* @return string

*/

protected function getAvailablePageWrapper($url, $page)

{

return '<a href="' . htmlentities($url) . '">' . $page . '</a>';

}

/**

* 生成一个禁用的按钮

*

* @param string $text

* @return string

*/

protected function getDisabledTextWrapper($text)

{

return '<a class="layui-laypage-prev" >' . $text . '</a>';

}

/**

* 生成一个激活的按钮

*

* @param string $text

* @return string

*/

protected function getActivePageWrapper($text)

{

return '<span class="layui-laypage-curr"><em class="layui-laypage-em"></em><em>' . $text . '</em></span>';

}

/**

* 生成省略号按钮

*

* @return string

*/

protected function getDots()

{

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);

}

}

视图

<div class="layui-box layui-laypage layui-laypage-default">{$page}</div>

tp5 设置layui分页的更多相关文章

  1. tp5的 LayUI分页样式实现

    1.先配置你的分页参数: //分页配置 'paginate'      => [ 'type'      => 'Layui', 'var_page'  => 'page', 'li ...

  2. LayUI分页,LayUI动态分页,LayUI laypage分页,LayUI laypage刷新当前页

    LayUI分页,LayUI动态分页,LayUI laypage分页,LayUI laypage刷新当前页 >>>>>>>>>>>> ...

  3. 最易懂的layui分页

    该篇文章是在layui前端框架之分页基础上简洁化和详细化. 首先该示例采用的是Spring+MyBatis Plus+SpringMVC(常规的SSM框架),持久层换成MyBatis也行. 至于lay ...

  4. tp5 使用paginate分页获取数据对象之后 如何对对象进行数据添加

    tp5 使用paginate分页获取数据对象之后 如何对对象进行数据添加 大家都知道,在使用tp5的paginate获取分页数据之后,得到的是一个数据对象,但有时会碰到要对数据对象进行二次加工的情况, ...

  5. springBoot mybatis mysql pagehelper layui 分页

    <!-- 加入 pagehelper 分页插件 jar包--><dependency> <groupId>com.github.pagehelper</gro ...

  6. 设置layui表格cell的内边距

    /*设置layui表格cell的内边距*/ .layui-table-cell { height: 50px !important; line-height: 50px !important; }

  7. TP5之使用layui分页样式

    1.首先你得引入layui文件吧 2.在 application\config.php 中配置,像这样,,, 3.controller中这样写 $data = Db::table($table) -& ...

  8. tp5 集成 layui富文本编辑器

    编辑器地址:http://www.layui.com/doc/modules/layedit.html 一睹芳容 1 去官网:http://www.layui.com/     下载layui ├─c ...

  9. layui分页

    毕业已经两年,期间经历了很多.一个人欢笑与哭泣,在墙角.在路边.在床上.每天搭乘首班车来到公司,每天无数次反省自己,每天每天再问自己为什么活着. 一.下载并引用css和js 地址:点我 <lin ...

随机推荐

  1. Kettle系列: Kettle并行执行Trans后的合并问题

    我们在作业开发中为了处理效率, 经常需要并行执行一些trans, 等它们执行完毕后, 需要执行另外一些trans, 从流程上也就是分支+汇合. 粗看起来很简单, Kettle中对接一下这些组件就搞定了 ...

  2. 向量空间模型(Vector Space Model)的理解

    1. 问题描述 给你若干篇文档,找出这些文档中最相似的两篇文档? 相似性,可以用距离来衡量.而在数学上,可使用余弦来计算两个向量的距离. \[cos(\vec a, \vec b)=\frac {\v ...

  3. Java面试题系列(四)强引用、软引用、弱引用、幻象引用有什么区别?

    序言 资料 https://blog.csdn.net/weixin_38729727/article/details/82259507

  4. Extjs 设置GridPanel单元格可选择高兼容写法

    网上大部分都是这种 <style type= "text/css" > .x-selectable, .x-selectable * { -moz-user-selec ...

  5. Immunity Debugger学习

    1.Immunity Debugger简介 Immunity Debugger软件专门用于加速漏洞利用程序的开发,辅助漏洞挖掘以及恶意软件分析.它具备一个完整的图形用户界面,同时还配备了迄今为止最为强 ...

  6. 【bzoj 3786】星系探索

    Description 物理学家小C的研究正遇到某个瓶颈. 他正在研究的是一个星系,这个星系中有n个星球,其中有一个主星球(方便起见我们默认其为1号星球),其余的所有星球均有且仅有一个依赖星球.主星球 ...

  7. Java SE之正则表达式二:匹配

    package demo.regex; import java.util.regex.Pattern; /* 正则表达式:匹配 */ public class RegexMatchesDemo { / ...

  8. MacOS安装kafka可视化工具Kafka Tool

    1 下载地址 http://www.kafkatool.com/download.html 2 下载dmg包,选择对应版本,我的kafka是2.1的版本,所以选择了Kafka Tool 2.0.4 3 ...

  9. git 配置 BeyondCompare

    安装 Beyond Compare 4 配置 git git config --global merge.tool bc3 git config --global mergetool.bc3.path ...

  10. Log4Net配置日志

    1.log4net 1)新建一个Net空白项目,在引用出点击管理NuGet程序包,搜索log4net并安装 2)建立log4net.config配置文件 在configuration里面添加如下代码, ...