TP5框架如何实现自定义分页样式
创始人
2024-11-30 00:40:54
0次

1. 在extend\目录下创建page目录,在page目录下创建Page.php文件,将以下代码放入文件中。

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 . "条数据

";   }     /**    * 页码按钮    * @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%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()         );       }     }   }     /**    * 生成一个可点击的按钮    *    * @param string $url    * @param int  $page    * @return string    */   protected function getAvailablePageWrapper($url, $page)   {     return '' . $page . '';   }     /**    * 生成一个禁用的按钮    *    * @param string $text    * @return string    */   protected function getDisabledTextWrapper($text)   {     return '' . $text . '

';   }     /**    * 生成一个激活的按钮    *    * @param string $text    * @return string    */   protected function getActivePageWrapper($text)   {     return '' . $text . '';   }     /**    * 生成省略号按钮    *    * @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 '        .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}     ';   } }

2. 修改  application\config.php  中的配置文件即可

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

3. 分页样式为 TP5框架如何实现自定义分页样式

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...