<?php // +---------------------------------------------------------------------- // | Refer to thinkphp pagination class change // +---------------------------------------------------------------------- // | There are two styles: 1, the face page number is always in the middle. 2. When the page number on both sides of the page, automatically page (default). // +---------------------------------------------------------------------- // | Author:zbseoag <zbsoeagy@qq.com> // +---------------------------------------------------------------------- $Id: page.class.php 2013-05-26 00:08:49 Session_Start (); The session is enabled because you want to record whether the user is moving forward or paging backwards. Class page{ Public $page; Current page
Public $nextPage; Previous page
Public $prevPage; Next page
Public $pageMax; Max Page
Public $startPage; Paging Bar at least
Public $endPage; Pagination Bar Stop Code
Public $style; Style: $style = mid
public $parameter;//number of parameters to take when page jumps
public $varPage;//Default paging variable
public $url = null; Specify URL address
protected $config = Array (
' Header ' => ' record ', ' prev ' => ' prev ', ' Next ' => ' Next ', ' first ' => ' home ', ' last ' => ' end ',
' Theme ' => '%records%%header%%page%/%pagemax% page%firstpage%%prevpage%%linkpage%%nextpage%%lastpage% '
);
/**
+----------------------------------------------------------
* Frame-making function
+----------------------------------------------------------
* Total number of records @param $records
* @param $pageSize Display the number of records per page
* @param $pageVal The parameters of the paging jump
* @param $parameter Additional parameters
+----------------------------------------------------------
*/
function __construct ($records, $pageSize, $pageVal = ' P ', $parameter = null) {
$this->records = $records;
$this->pagemax = ceil ($records/$pageSize);
$this->page= Max ($_get[$pageVal]), 1); Minimum of 1
$this->page = min ($this->page, $this->pagemax); Max for last
$this->nextpage = $this->page + 1;
$this->prevpage = $this->page-1;
$this->varpage = $pageVal; Default paging variable name
$this->parameter = $parameter; Additional URL parameters
}
/**
+----------------------------------------------------------
* Set Style
+----------------------------------------------------------
* @param $name The name of the built-in parameter
* @param $value given parameter values
+----------------------------------------------------------
*/
function Setconfig ($name, $value) {
if (Isset ($this->config[$name])) {
$this->config[$name] = $value;
}
}
/**
+----------------------------------------------------------
* Paging Display output
+----------------------------------------------------------
* @param $length Paging length
+----------------------------------------------------------
* @param $hide Whether or not to hide the previous page, such as: The current is the first page, hide the previous page
+----------------------------------------------------------
*/
Function Show ($length, $hide = False) { if (0 = $this->records) return "; Empty ($this->url)? $this->url = $_server[' Request_uri ']: null; $url = $this->url. (Strpos ($this->url, '? ')? ': '? '). $this->parameter; $parse = Parse_url ($url); if Isset ($ parse[' query ']) { parse_str ($parse [' Query '], $params); unset ($params [$this->varpage]); $url = $parse [' Path ']. Http_build_query ($params); } if (' mid ' = = $this->style) {//Current page Center
if ($length% 2!= 0) {
$midder = Ceil ($length/2);
$big _repair = $midder-1;//When the above is rounded by one method, this is minus 1, and the other is plus 1.
}else{
$big _repair = $midder = $length/2;
}
$SML _repair = $midder-1; This is a little patch.
$this->startpage = ($this->page + $midder) > $this->pagemax? $this->pagemax-$length: $this->page-$sml _repair;
$this->endpage = ($this->page < $midder)? $length: $this->page + $big _repair;
}else{//Last page paging
$this->startpage = ($this->page >= $length)? $_session[' startpage ': 1;
$this->endpage = $this->startpage + $length-1;
$this->lastpage = isset ($_session[' lastpage '))? $_session[' lastpage ': 1; The last page number
$_session[' lastpage ' = $this->page; Save current page
if ($this->lastpage < $this->page) {//Back Page
if ($this->page >= $this->endpage) {
$this->startpage = $_session[' startpage '] = $this->page;
$this->endpage = $this->startpage + $length-1;
}
}elseif ($this->lastpage = = $this->page) {//Toggle
if ($this->page = = $this->endpage) {
$this->startpage = $_session[' startpage '] = $this->page;
$this->endpage = $this->startpage + $length-1;
}else{
$this->startpage = $_session[' startpage '] = $this->page-$length + 1;
$this->endpage = $this->startpage + $length-1;
}
}else{//front Page
if ($this->page = = $this->startpage) {
$this->startpage = $_session[' startpage '] = $this->page-$length + 1;
$this->endpage = $this->startpage + $length-1;
}
}
Echo ' Start Page: '. $this->startpage. ' <br/> ';
Echo ' last page: '. $this->lastpage. ' <br/> ';
}
Fix it, please.
$this->startpage = min ($this->pagemax-$length + 1, $this->startpage); Biggest
$this->startpage = max ($this->startpage, 1);//min for first page (max first, minimum)
$this->endpage = $this->startpage + $length-1;
$this->endpage = min ($this->pagemax, $this->endpage); Max for last
$_session[' startpage ' = $this->startpage; After correction, save again
Echo ' Start Page: '. $this->startpage. ' <br/> ';
Echo ' last page: '. $this->lastpage. ' <br/> ';
if ($this->page <= 1) {//If already home
$firstPage = ' <span> '. $this->config[' a '. ' </span> ';
$prevPage = ' <span> '. $this->config[' prev ']. ' </span> ';
}else{
$firstPage = "<span><a href= ' $url & $this->varpage=1 ' >". $this->config[' a '. ' </a> ';
$prevPage = "<span><a href= ' $url & $this->varpage= $this->prevpage ' > '. $this->config[' prev '] .' </a> ';
}
if ($this->page >= $this->pagemax) {//If already the last page
$nextPage = ' <span> '. $this->config[' next '. ' </span> ';
$lastPage = ' <span> '. $this->config[' last ']. ' </span> ';
}else{
$lastPage = "<a href= ' $url & $this->varpage= $this->pagemax ' > '. $this->config[' last ']. ' </a> ';
$nextPage = "<a href= ' $url & $this->varpage= $this->nextpage ' > '. $this->config[' next ']. ' </a> ';
}
if ($hide) {//If hidden mode
($this->nextpage >= $this->pagemax)? $nextPage = ': null;
($this->prevpage < 1)? $prevPage = ': null;
} for ($i = $this->startpage; $i <= $this->endpage; $i + +) {
if ($this->page = = $i)
$linkPage. = "<a class= ' href= ' $url & $this->varpage= $i ' > $i </a> ';
Else
$linkPage. = "<a href= ' $url & $this->varpage= $i ' > $i </a> ';
}
$search = Array ('%records% ', '%header% ', '%page% ', '%pagemax% ', '%firstpage% ', '%prevpage% ', '%linkpage% ', '%nextpage% ') , '%lastpage% ');
$replace = Array ($this->records, $this->config[' header '), $this->page, $this->pagemax, $firstPage, $ PrevPage, $linkPage, $nextPage, $lastPage);
$PAGESTR = Str_replace ($search, $replace, $this->config[' theme ')); return $pageStr; }
} $page = new Page (340, 10); $theme = '%records%%header%%page%/%pagemax% page%firstpage%%prevpage%%linkpage%%nextpage%%lastpage% '; $page->setconfig (' theme ', $theme); You can modify the style, such as: When not the last page is, you can delete%lastpage%, or change the order of position $page->setconfig (' Last ', ' End '); Customizable text: ' Header ' = ' record ', ' prev ' = ' prev ', ' next ' = ' next ', ' first ' = ' home ', ' last ' = ' End ' $page->url = ' http://localhost/test.php '; echo $page->show (10); ?> <style> a,span{margin:2px 5px;} . current{color:red;} </style> |