\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. impala系列:impala特有的操作符

    --=======================Impala 特有的操作符--=======================ILIKE 操作符, 忽略大小写的 like 操作符.REGEXP 操作符 ...

  2. CorelDrawX8安装时提示已安装另一个版本

    (1)首先卸载VIsualC++ 2015 运行库. (2)如果有VisualC++ 2017运行库,卸载VisualC++2017运行库,即可.

  3. AOSP android 源码下载

    (1)下载 repo 工具 mkdir ~/bin PATH=~/bin:$PATH curl https://storage.googleapis.com/git-repo-downloads/re ...

  4. 【LeetCode】134.Gas Station

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

  5. 20155324 2016-2017-2 《Java程序设计》第5周学习总结

    20155324 2016-2017-2 <Java程序设计>第5周学习总结 教材学习内容总结 try.catch 1.求平均数程序示例 import java.util.Scanner; ...

  6. MySQL api

    今天看去年年中写的代码,留意到一个关键时刻能提高效率的api:on duplicate key update: 语法: INSERT INTO INSERT INTO g_iot_user_build ...

  7. 双系统中卸载Ubuntu后又efi系统分区删除方法

    参考:https://blog.csdn.net/qq_28057541/article/details/51723914 首先 window键(窗口键) + R ,然后输入 Diskpart 打开命 ...

  8. 「NowCoder Contest 295」H. Playing games

    还是见的题太少了 「NowCoder Contest 295」H. Playing games 题意:选出尽量多的数使得异或和为$ 0$ $ Solution:$ 问题等价于选出尽量少的数使得异或和为 ...

  9. 电路板上的元件R,T,D,C,U

    参考链接: https://zhidao.baidu.com/question/194132005.html

  10. mysql原理~创建用户的那些事情

    一 简介:mysql是如何创建用户的二 基本语法:  1 grant 权限 on db.table to 'user'@'ip' identified by 'password'     目的 创建用 ...