当前位置:网站首页>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);
}
}
边栏推荐
- Web test learning notes 01
- The solution to the memory exhaustion problem when PHP circulates a large amount of data
- 使用transform:translate()出现内容模糊问题
- For enterprise operation and maintenance security, use the cloud housekeeper fortress machine!
- 第21回---第30回
- Log management
- Your password does not satisfy the current policy requirements (modify MySQL password policy setting simple password)
- TP5 -- query field contains a certain --find of search criteria_ IN_ SET
- const小结
- COMS Technology
猜你喜欢

Your password does not satisfy the current policy requirements (modify MySQL password policy setting simple password)

Pychart import existing project

DeFi安全之DEX与AMMs

Mysql5.7 master-slave hot standby settings on CentOS

Yys mouse connector

Time series ARIMA model

Boolean value

企业运维安全就用行云管家堡垒机!

centos上mysql5.7主从热备设置

Flask connects to existing tables in MySQL database
随机推荐
ADAMS中转动整个模型
Draw circuit diagram according to Verilog code
JSP基础
Solve the problem that Flink cannot be closed normally after startup
Pychart imports the existing local installation package
企业运维安全就用行云管家堡垒机!
Axure install Icon Font Catalog
Mapreduce实例(二):求平均值
Vant UI toast and dialog use
Crmeb Pro v1.4 makes the user experience more brilliant!
word中插入度的方法
Solve the compilation warning of multiple folders with duplicate names under the openwrt package directory (call subdir function)
编码技巧——全局异常捕获&统一的返回体&业务异常
Reduce PDF document size (Reprint)
SolidWorks simulation curve attribute setting
Yys mouse connector
Time series ARIMA model
const小结
2021-03-09
Openwrt new platform compilation