\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. SQL Server进阶 索引

    create unique index 和create index 的区别? CREATE UNIQUE INDEX ProviderInfo_Id_uindex ON dbo.ProviderInf ...

  2. RMQ st算法 区间最值模板

    #include<bits/stdc++.h> ; ; int f[N][Logn],a[N],lg[N],n,m; int main(){ cin>>n>>m; ...

  3. sql库连sql中间库连orcle库增删改查方案

    ---中间库建立存储过程create procedure Proc_exec@SQL nvarchar(MAX)ASexec(@SQL) GO---web服务器执行语句 --查 select * fr ...

  4. JavaScript之Ajax Util

    ajax(即:Asynchronous JavaScript and XML(异步的 JavaScript 和 XML))经常在用,却经常忽略了底层的实现机制,今日写个小工具,大家也可拿去使用,如果写 ...

  5. 贝叶斯网络与LDA

    一.一些概念 互信息: 两个随机变量x和Y的互信息,定义X, Y的联合分布和独立分布乘积的相对熵. 贝叶斯公式: 贝叶斯带来的思考: 给定某些样本D,在这些样本中计算某结论出现的概率,即 给定样本D ...

  6. java后台获取参数乱码

    String title = getParam("searchTitle"); title = new String(title.getBytes("iso8859-1& ...

  7. scrapy基础 之 爬虫入门:先用urllib2来理解爬虫

    1,概念理解 爬虫:抓取和保存网页信息,用户看到的网页实质是由 HTML 代码构成的,爬虫爬来的便是这些内容,通过分析和过滤这些 HTML 代码,实现对图片文字等资源的获取. URL:即统一资源定位符 ...

  8. shell编程 之 输入输出重定向

    1 输入输出重定向 标准输入:从终端得到命令,对于计算机来说,是从终端获得了命令,执行完了以后,结果和执行状态或者错误提示又会发回终端,这叫标准输出. 输入输出重定向就是从终端以外的别的地方得到输入, ...

  9. Android 5.0以上Material Design 沉浸式状态栏

    偶然在知乎上看到这个问题,Android 5.0 如何实现将布局的内容延伸到状态栏,之前也见过多个应用的这个功能,但是知乎上的答案却没有一个真正实现此功能的一类是把标题栏设置App主题颜色,一类是提取 ...

  10. xht37的码风

    写在前面 众所周知,在 Dev-C++ 上有一个代码格式化的功能,快捷键Ctrl+Shift+A 我的码风致力于写出格式化后毫无变化的代码,这被认为是标准代码 同时,对不可格式化的部分(如空格),我同 ...