\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. JS创建对象之稳妥构造函数模式

    所谓稳妥对象,指的是没有公共属性,而且其方法也不引用this的对象 function Person(name, age, job) { // 创建要返回的对象 var o = new Object() ...

  2. 【LeetCode】134.Gas Station

    Problem: There are N gas stations along a circular route, where the amount of gas at station i is ga ...

  3. matplotlib-2D绘图库学习目录

    matplotlib的安装和 允许中文及几种字体 散点图 直线和点 子图 点的形状 条形图 堆叠条形图 直方图 颜色和样式字符串 饼状图  画多个图  画网格 线的形状  图例  坐标轴  画注释   ...

  4. luogu P4770 [NOI2018]你的名字

    传送门 upd 19.4.24: WC这个做法真的有问题,不往回跳会WA是因为一开始跳到了S[1...l-1]所对应的点,然后往后接字符的时候可能会因为不在正确的endpos中,然后往回跳过头,其实一 ...

  5. TensorFlow从入门到理解(五):你的第一个循环神经网络RNN(回归例子)

    运行代码: import tensorflow as tf import numpy as np import matplotlib.pyplot as plt BATCH_START = 0 TIM ...

  6. git详细介绍

    Git管理我们的代码会经历三个不过程 1. 工作区:没有提交的代码就是存放的工作区 2. 暂存区:通过 git add 文件名 命令提交代码该文件就放在暂存区 3. 历史区:通过 git commit ...

  7. windows平台下利用Nginx做负载均衡

    1.下载nginx(http://nginx.org/en/download.html)安装包,解压,并使用cmd命令转到nginx.exe所在的目录 2.执行cmd命令start nginx启动ng ...

  8. Mysql大文本类型

    TEXT 一个BLOB或TEXT列,最大长度为65535(2^16-1)个字符. MEDIUMTEXT 一个BLOB或TEXT列,最大长度为16777215(2^24-1)个字符. LONGTEXT ...

  9. Android程序破解思路

    Android程序的一般分析与破解流程 1.如何寻找突破口是分析一个程序的关键.错误提示信息左右一般是程序验证逻辑的核心代码. 2.错误提示是android程序的字符串资源,字符串有可能硬编码到源码中 ...

  10. 全国人口 信息(NCIIC)接口开发纪要

    阶段一:根据wsdl2java命令解析https://ws.nciic.org.cn/nciic_ws/services/NciicServices?wsdl以生成接口调用的对象类: wsdl2jav ...