1.先配置你的分页参数:

//分页配置

'paginate'      => [

'type'      => 'Layui',

'var_page'  => 'page',

'list_rows' => 15,

'newstyle'  => true,

],

2. 下载文件(Layui.php),并复制到 \thinkphp\library\think\paginator\driver

3. 模板文件里正常使用分页即可

PHP:

// 获取分页显示
$page = $inquiry_list->render();
// 模板变量赋值
$this->assign('list', $inquiry_list);
$this->assign('page', $page); HTML:
<div class="layui-box layui-laypage layui-laypage-default">{$page}</div>



 分页源码: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);
}
}

tp5的 LayUI分页样式实现的更多相关文章

  1. TP5之自定义分页样式

    分页样式为 在extend\目录下创建page目录,在page目录下创建Page.php文件,将以下代码放入文件中. <?php namespace page; use think\Pagina ...

  2. TP5之使用layui分页样式

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

  3. tp5 设置layui分页

    \thinkphp\library\think\paginator\driver 添加 Layui.php <?php namespace think\paginator\driver; use ...

  4. tp5.0分页样式调控

    基础的分页调用 /** * 控制器部分代码 */ //实例化模型 $areasModel=new Areas(); //分页数据集 $listarea=$areasModel->paginate ...

  5. DataPager 分页样式(css)

    <asp:DataPager ID="> <Fields> <asp:NextPreviousPagerField ShowFirstPageButton=&q ...

  6. php分页类代码带分页样式效果(转)

    php分页类代码,有漂亮的分页样式风格 时间:2016-03-16 09:16:03来源:网络 导读:不错的php分页类代码,将类文件与分页样式嵌入,实现php查询结果的精美分页,对研究php分页原理 ...

  7. 打造简单实用的Thinkphp分页样式(Bootstrap版本)

    先吐槽一下ThinkPHP3.1版的分页样式,虽然看起来也很简单大方,但是所有的页码全是使用简单的数字,之间的空隙比较小,不大容易点,还有那个“前5页”和“后5页”显得有点多余,因为点击当前显示第一页 ...

  8. bootstrap 分页样式代码

    bootstrap 分页样式代码,废话不多说,直接上源码 <!DOCTYPE html> <html> <head> <title>Bootstrap ...

  9. 帝国cms 列表页分页样式修改美化【2】

    上一篇(帝国cms 列表页分页样式修改美化[1])中我们已经对分页说了一个大概,下面我们就自己动手弄一个分页把: 第一步:进入帝国cms后台,点击系统设置->系统参数设置->信息设置:里面 ...

随机推荐

  1. MySQL索引及优化(1)存储引擎和底层数据结构

    在昨天的面试中问到了MySQL索引怎么优化(查询很慢怎么办),回答的很不理想,所以今天来总结几篇关于MySQL索引的知识. 1.什么是索引? 首先我们一定要明确什么是索引?我自己的总结就是索引是一种数 ...

  2. Java面试题小结(一)

    ---恢复内容开始--- 1.用Java解析xml有几种方式,实现场景.区别以及优缺点: 有四种 分别是JDOM.SEX.DOM.JDOM4J 实现场景: JDOM:实现功能简单的地方,例如:解析: ...

  3. 基于SpringCloud分布式架构

    基于SpringCloud分布式架构 为什么要使用分布式架构 Spring Cloud 专注于提供良好的开箱即用经验的典型用例和可扩展性机制覆盖 分布式/版本化配置 服务注册和发现 路由 Servic ...

  4. 进程间的通信——pipe通信

    当进程创建管道文件后,其建立的子进程自动继承该文件. 管道通信分为命名管道和未命名管道,他们的区别是命名管道在当创建他的进程结束后,系统仍存有该文件 管道的命令格式为 pipe(fds) 其中 fds ...

  5. JAVA局部变量和成员变量的区别

    成员变量与局部变量的区别 1.在类中的位置不同 成员变量:在类中方法外面 局部变量:在方法或者代码块中,或者方法的声明上(即在参数列表中) 2.在内存中的位置不同 成员变量:在堆中(方法区中的静态区) ...

  6. Spring Boot集成Shrio实现权限管理

    Spring Boot集成Shrio实现权限管理   项目地址:https://gitee.com/dsxiecn/spring-boot-shiro.git   Apache Shiro是一个强大且 ...

  7. 02.Django-模板

    模板 1. 简介 模板由HTML代码和逻辑控制代码构成 同一个模板,可以有多个上下文,就可以通过穿件模板对象来渲染多个上下文 创建一个模板就可以多次调用render()方法来渲染上下文 Django模 ...

  8. 大数据平台比较-CDH,HDP

    主要的不同点 apache Ambari ClouderaManager Express(免费版) 配置版本控制和历史记录 支持 不支持 二次开发 支持 不支持 集成 支持 no (不支持redis. ...

  9. 【转】最长公共子序列(LCS),求LCS长度和打印输出LCS

    求LCS的长度,Java版本: public static int LCS(int[]a,int[] b) { int [][]c=new int[a.length+1][b.length+1]; f ...

  10. 一个基类Person的多个派生类 代码参考

    #include <iostream> #include <cstring> using namespace std; class Person { protected: ch ...