当前位置:网站首页>TP5 rewrite paging
TP5 rewrite paging
2022-07-27 16:24:00 【Collect and learn by yourself】
<?php
// I saw it on the Internet at that time , Forgot the address of the original post , stay thinkphp/library/think/paginator/driver/ Let's create BootstrapDetailed.php Then copy the code and reference it in the page , example :
//$user=Db::name('user')->where($where)->paginate(5, false, ['query' => request()->param(),'type'=>'BootstrapDetailed',]);
namespace think\paginator\driver;
use think\Paginator;
class BootstrapDetailed extends Paginator
{
/**
* Previous button
* @param string $text
* @return string
*/
protected function getPreviousButton($text = " The previous page ")
{
if ($this->currentPage() <= 1) {
return $this->getDisabledTextWrapper($text);
}
$url = $this->url(
$this->currentPage() - 1
);
return $this->getPageLinkWrapper($url, $text);
}
// Total label
protected function totalshow()
{
// $totalhtml="<li class=\"disabled\"><span> common ".$this->total." Bar record    The first ".$this->currentPage()." page / common ".$this->lastPage()." page </span></li>";
$totalhtml="<li class=\"disabled\"><span style='font-size: 16px;border:none;'>   common ".$this->lastPage()." page   ".$this->total." Bar record   </span><input type='hidden' value='".$this->lastPage()."' id='maxNum'></li>";
return $totalhtml;
}
// Tail page label
protected function showlastpage($text = ' Last ')
{
if($this->currentPage()==$this->lastPage())
{
return $this->getDisabledTextWrapper($text);
}
$url = $this->url($this->lastPage());
return $this->getPageLinkWrapper($url, $text);
}
// Home tag
protected function showfirstpage($text = ' first page ')
{
if($this->currentPage()==1)
{
return $this->getDisabledTextWrapper($text);
}
$url = $this->url(1);
return $this->getPageLinkWrapper($url, $text);
}
// Last five pages
protected function afivepage($text = ' Last five pages ')
{
if($this->lastPage()<$this->currentPage()+5)
{
// return $this->getDisabledTextWrapper($text);
}
$url = $this->url($this->currentPage()+5);
// return $this->getPageLinkWrapper($url, $text);
}
// First five pages
protected function bfivepage($text = ' First five pages ')
{
if($this->currentPage()<5)
{
// return $this->getDisabledTextWrapper($text);
}
$url = $this->url($this->currentPage()-5);
// return $this->getPageLinkWrapper($url, $text);
}
/**
* Next button
* @param string $text
* @return string
*/
protected function getNextButton($text = ' The next page ')
{
if (!$this->hasMore) {
return $this->getDisabledTextWrapper($text);
}
$url = $this->url($this->currentPage() + 1);
return $this->getPageLinkWrapper($url, $text);
}
// Jump to which page
protected function gopage()
{
return $gotohtml="<li><form action='' method='get' class='que'><span class='gopage' style='font-size: 16px;'> To the first <input type='text' name='page'> page <input type='submit' value=' determine '> </span></form></li>";
return $totalhtml;;
}
/**
* Page buttons
* @return string
*/
protected function getLinks()
{
if ($this->simple)
return '';
$block = [
'first' => null,
'slider' => null,
'last' => null
];
$side = 2;
$window = $side * 2;
if ($this->lastPage < $window +1) {
$block['slider'] = $this->getUrlRange(1, $this->lastPage);
} elseif ($this->currentPage <= $window-1) {
$block['slider'] = $this->getUrlRange(1, $window + 1);
} elseif ($this->currentPage > ($this->lastPage - $window+1)) {
$block['slider'] = $this->getUrlRange($this->lastPage - ($window), $this->lastPage);
} else {
$block['slider'] = $this->getUrlRange($this->currentPage - $side, $this->currentPage + $side);
}
$html = '';
if (is_array($block['first'])) {
$html .= $this->getUrlLinks($block['first']);
}
if (is_array($block['slider'])) {
$html .= $this->getUrlLinks($block['slider']);
}
if (is_array($block['last'])) {
$html .= $this->getUrlLinks($block['last']);
}
return $html;
}
/**
* Render paging html
* @return mixed
*/
public function render()
{
if ($this->hasPages()) {
if ($this->simple) {
return sprintf(
'<ul class="pager">%s %s %s</ul>',
$this->getPreviousButton(),
$this->getNextButton()
);
} else {
return sprintf(
'<ul class="pagination"> %s %s %s %s %s %s %s %s %s</ul>',
// first page
$this->showfirstpage(),
// The previous page
$this->getPreviousButton(),
// First five pages
$this->bfivepage(),
// Page number
$this->getLinks(),
// Last five pages
$this->afivepage(),
// The next page
$this->getNextButton(),
// The last page
$this->showlastpage(),
// Display quantity page information
$this->totalshow(),
// Finally, add another parameter %s It can show which page to jump to
$this->gopage()
);
}
}
}
/**
* Generate a clickable button
*
* @param string $url
* @param int $page
* @return string
*/
protected function getAvailablePageWrapper($url, $page)
{
return '<li><a href="' . htmlentities($url) . '">' . $page . '</a></li>';
}
/**
* Generate a disabled button
*
* @param string $text
* @return string
*/
protected function getDisabledTextWrapper($text)
{
return '<li class="disabled"><span>' . $text . '</span></li>';
}
/**
* Generate an active button
*
* @param string $text
* @return string
*/
protected function getActivePageWrapper($text)
{
return '<li class="active"><span>' . $text . '</span></li>';
}
/**
* Generate ellipsis button
*
* @return string
*/
protected function getDots($text = '...')
{
//$url = $this->url($this->currentPage() + 1);
// return $this->getPageLinkWrapper($url, $text);
return $this->getDisabledTextWrapper('...');
}
/**
* Batch generate page number button .
*
* @param array $urls
* @return string
*/
protected function getUrlLinks(array $urls)
{
$html = '';
foreach ($urls as $page => $url) {
$html .= $this->getPageLinkWrapper($url, $page);
}
return $html;
}
/**
* Generate normal page number button
*
* @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);
}
}
边栏推荐
- DRF use: get request to get data (small example)
- A powerful web vulnerability scanning and verification tool (vulmap)
- Common Oracle statements
- Analysis of PHP keyword replacement classes (avoid repeated replacement, keep and restore the original links)
- Draw circuit diagram according to Verilog code
- Mapreduce实例(一):WordCount
- 百度图片复制图片地址
- Some queries of TP5
- Multiline text overflow dotting
- JSP Foundation
猜你喜欢

Flume incrementally collects MySQL data to Kafka

For enterprise operation and maintenance security, use the cloud housekeeper fortress machine!

2.2 JMeter基本元件

第21回---第30回

flume增量采集mysql数据到kafka

web测试学习笔记01

Keil implements compilation with makefile

Pychart import existing project

Introduction to JWT

DRF use: get request to get data (small example)
随机推荐
Easy to understand, distinguish between ++i and I++
Text capture picture (Wallpaper of Nezha's demon child coming to the world)
Nacos
matlab legend用法
Openwrt new platform compilation
webRTC中的coturn服务安装
Introduction and use of redis
C语言程序设计(第三版)
实现浅拷贝和深拷贝+
It can carry 100 people! Musk releases the strongest "starship" in history! Go to Mars as early as next year!
DEX and AMMS of DFI security
插入word中的图片保持高dpi方法
2021-03-09
Delete node quickly and efficiently_ modules
Install MySQL using CentOS yum
Common tool classes under JUC package
Nacos
编码技巧——全局日志开关
centos yum方式安装mysql
Openwrt adds RTC (mcp7940 I2C bus) drive details