栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP > php开源框架 > thinkphp

ThinkPHP5自定义分页类教程详解用法

thinkphp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

自定义分页类


效果图


blob.png



第一步:创建文件Page.php,将其放到extendpage,这里也可以自己决定,命名空间对了就行


// +----------------------------------------------------------------------

use thinkPaginator;

class Page extends Paginator
{

    //首页
    protected function home() {
        if ($this->currentPage() > 1) {
            return "url(1) . "' title='首页'>首页";
        } else {
            return "

首页

";         }     }     //上一页     protected function prev() {         if ($this->currentPage() > 1) {             return "url($this->currentPage - 1) . "' title='上一页'>上一页";         } else {             return "

上一页

";         }     }     //下一页     protected function next() {         if ($this->hasMore) {             return "url($this->currentPage + 1) . "' title='下一页'>下一页";         } else {             return"

下一页

";         }     }     //尾页     protected function last() {         if ($this->hasMore) {             return "url($this->lastPage) . "' title='尾页'>尾页";         } else {             return "

尾页

";         }     }     //统计信息     protected function info(){         return "共" . $this->lastPage .             "页" . $this->total . "条数据

";     }          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;     }          public function render()     {         if ($this->hasPages()) {             if ($this->simple) {                 return sprintf(                     '%s%s %s %s',                     $this->css(),                     $this->prev(),                     $this->getLinks(),                     $this->next()                 );             } else {                 return sprintf(                     '%s%s %s %s %s %s %s',                     $this->css(),                     $this->home(),                     $this->prev(),                     $this->getLinks(),                     $this->next(),                     $this->last(),                     $this->info()                 );             }         }     }          protected function getAvailablePageWrapper($url, $page)     {         return '' . $page . '';     }          protected function getDisabledTextWrapper($text)     {         return '' . $text . '

';     }          protected function getActivePageWrapper($text)     {         return '' . $text . '';     }          protected function getDots()     {         return $this->getDisabledTextWrapper('...');     }          protected function geturlLinks(array $urls)     {         $html = '';         foreach ($urls as $page => $url) {             $html .= $this->getPageLinkWrapper($url, $page);         }         return $html;     }          protected function getPageLinkWrapper($url, $page)     {         if ($page == $this->currentPage()) {             return $this->getActivePageWrapper($page);         }         return $this->getAvailablePageWrapper($url, $page);     }          protected function css(){         return '               .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}         ';     } }


第二步:修改配置文件

//分页配置  
   'paginate'               => [  
       'type'      => 'pagePage',//分页类  
       'var_page'  => 'page',  
       'list_rows' => 15,  
   ],


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/824986.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号