TP5 分页样式[通俗易懂]

TP5 分页样式[通俗易懂]自定义分页类放到extend\page\,这里也可以自己决定,命名空间对了就行    在extend\page\下新建Page.php把以下代码粘过去<?phpnamespacepage;//+———————————————————————-//|ThinkPHP[WECAN…

大家好,又见面了,我是你们的朋友全栈君。

自定义分页类 放到extend\page\,这里也可以自己决定,命名空间对了就行     在extend\page\下新建Page.php把以下代码粘过去

<?php
namespace page;
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: zhangyajun <448901948@qq.com>
// +----------------------------------------------------------------------
use think\Paginator;
class Page extends Paginator
{
    //首页
    protected function home() {
        if ($this->currentPage() > 1) {
            return "<a href='" . $this->url(1) . "' title='首页'>首页</a>";
        } else {
            return "<p>首页</p>";
        }
    }
    //上一页
    protected function prev() {
        if ($this->currentPage() > 1) {
            return "<a href='" . $this->url($this->currentPage - 1) . "' title='上一页'>上一页</a>";
        } else {
            return "<p>上一页</p>";
        }
    }
    //下一页
    protected function next() {
        if ($this->hasMore) {
            return "<a href='" . $this->url($this->currentPage + 1) . "' title='下一页'>下一页</a>";
        } else {
            return"<p>下一页</p>";
        }
    }
    //尾页
    protected function last() {
        if ($this->hasMore) {
            return "<a href='" . $this->url($this->lastPage) . "' title='尾页'>尾页</a>";
        } else {
            return "<p>尾页</p>";
        }
    }
    //统计信息
    protected function info(){
        return "<p class='pageRemark'>共<b>" . $this->lastPage .
            "</b>页<b>" . $this->total . "</b>条数据</p>";
    }
    /**
     * 页码按钮
     * @return string
     */
    protected function getLinks()
    {
        $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(
                    '%s<div class="pagination">%s %s %s</div>',
                    $this->css(),
                    $this->prev(),
                    $this->getLinks(),
                    $this->next()
                );
            } else {
                return sprintf(
                    '%s<div class="pagination">%s %s %s %s %s %s</div>',
                    $this->css(),
                    $this->home(),
                    $this->prev(),
                    $this->getLinks(),
                    $this->next(),
                    $this->last(),
                    $this->info()
                );
            }
        }
    }
    /**
     * 生成一个可点击的按钮
     *
     * @param  string $url
     * @param  int    $page
     * @return string
     */
    protected function getAvailablePageWrapper($url, $page)
    {
        return '<a href="' . htmlentities($url) . '" title="第"'. $page .'"页" >' . $page . '</a>';
    }
    /**
     * 生成一个禁用的按钮
     *
     * @param  string $text
     * @return string
     */
    protected function getDisabledTextWrapper($text)
    {
        return '<p class="pageEllipsis">' . $text . '</p>';
    }
    /**
     * 生成一个激活的按钮
     *
     * @param  string $text
     * @return string
     */
    protected function getActivePageWrapper($text)
    {
        return '<a href="" class="cur">' . $text . '</a>';
    }
    /**
     * 生成省略号按钮
     *
     * @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);
    }
    /**
     * 分页样式
     */
    protected function css(){
        return '  <style type="text/css">
                .pagination p{
                    margin:0;
                    cursor:pointer
                }
                .pagination{
                    height:40px;
                    padding:20px 0px;
                }
                .pagination a{
                    display:block;
                    float:left;
                    margin-right:10px;
                    padding:2px 12px;
                    height:24px;
                    border:1px #cccccc solid;
                    background:#fff;
                    text-decoration:none;
                    color:#808080;
                    font-size:12px;
                    line-height:24px;
                }
                .pagination a:hover{
                    color:#077ee3;
                    background: white;
                    border:1px #077ee3 solid;
                }
                .pagination a.cur{
                    border:none;
                    background:#077ee3;
                    color:#fff;
                }
                .pagination p{
                    float:left;
                    padding:2px 12px;
                    font-size:12px;
                    height:24px;
                    line-height:24px;
                    color:#bbb;
                    border:1px #ccc solid;
                    background:#fcfcfc;
                    margin-right:8px;
                }
                .pagination p.pageRemark{
                    border-style:none;
                    background:none;
                    margin-right:0px;
                    padding:4px 0px;
                    color:#666;
                }
                .pagination p.pageRemark b{
                    color:red;
                }
                .pagination p.pageEllipsis{
                    border-style:none;
                    background:none;
                    padding:4px 0px;
                    color:#808080;
                }
                .dates li {font-size: 14px;margin:20px 0}
                .dates li span{float:right}
            </style>';
    }
}

修改配置文件 config.php

//分页配置
    'paginate'               => [
        'type'      => 'page\Page',
        'var_page'  => 'page',
        'list_rows' => 15,
        'newstyle'  => true,
    ],

效果图

TP5 分页样式[通俗易懂]

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/160642.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • origin带误差线的柱状图_怎么加误差棒

    origin带误差线的柱状图_怎么加误差棒软件版本:OriginPro2021b(64-bit)SR29.8.5.212(学习版)本期目标:接下来,正文开始:1,如图1,数据包含三个类型的数据列(X轴/Y轴/误差列)。A列表示X轴分组,B/D/F/H列表示Y轴数据,C/E/G/I列表示误差数据(此处为标准差)。注:此处数据设置为关键,需要按照正确,后面才可以绘制带有误差棒的分组柱状图。图1数据设置2,按照上图方式输入数据后,选中数据后,点击菜单栏——绘图——类别——多因子组柱状图-索引数据进行图形绘制,如图

    2022年9月29日
    2
  • vue子组件向父组件传值的三种方式_vue父页面传值到子页面

    vue子组件向父组件传值的三种方式_vue父页面传值到子页面1.用于子组件触发事件传递给父组件子组件:rowEvent里面也可以带参数事件treeData是携带的参数rowEvent(){this.$emit(‘rowEvent’,’treeData’’);},父组件:在父组件绑定自定义事件直接可以获取到rowEvents(obj){console.log(obj)},2.用ref(常用于不触发的事件)子组件定义个…

    2025年8月31日
    5
  • Ubuntu 安装 gcc-4.9.3-64-gnu

    Ubuntu 安装 gcc-4.9.3-64-gnu可能每个人的环境不一样,所以安装的方法有些许差别。我参考了多个网络上的教程,在自己的ubuntu虚拟机中安装了gcc-4.9.3-64-gnu,记录一下自己的安装过程。虚拟机中默认安装了gcc-5.4.0,我要安装gcc-4.9.3一、下载地址:wgethttp://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-4.9.3/gcc-4.9.3.tar.bz2由于是用的虚拟机,配置不是很高,自己是windows下载完毕拷贝进虚拟机中。gcc-gn

    2022年7月24日
    15
  • lnk2019无法解析的外部符号_declspec_error lnk1120无法解析的外部命令

    lnk2019无法解析的外部符号_declspec_error lnk1120无法解析的外部命令1.前言errorLNK2019:无法解析的外部符号这个错之前见过很多次,能知道最根本的原因在于链接过程中没有搜索到程序用到的库文件,即*.lib。笔记本重装了系统,有32Bit升到64Bit,运行VTK程序时,始终报错如下:1>  正在创建库E:\Driverprogram\imgport\Debug\imgport.lib和对象E:\Driverprog

    2022年10月6日
    1
  • android之activity的生命周期详解

    刚在看mars老师的视频,看到activity的生命周期,感觉挺有收获,就总结了一下.为了更清楚的看清楚工作的具体过程,举例如下:,建立两个activity,一个main,一个another,在main里面放置button加监听器跳转向another,在每个复写的activity的状态方法里都加一个log输出,比如onCrea

    2022年3月9日
    41
  • math.pow()函数用法[通俗易懂]

    Math.pow(底数,几次方)如:inta=3;intb=3;intc=Math.pow(a,b);就是3的三次方是多少;c最终为27;基础用法:用math.pow()实现数组的交错求和intant=0;a+=b[i]*math.pow(-1,ant);//实…

    2022年4月17日
    357

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号