This article mainly introduces the method of thinkPHP3.2 to realize the custom style of pagination, and analyzes the thinkPHP3.2 of the modification and use of the underlying framework code with the example form, and the friends can refer to the following
The examples in this article describe the way thinkPHP3.2 implements page-custom styles. Share to everyone for your reference, as follows:
The following is a Tp3.2 custom paging, this method is also after reading a netizen's blog was inspired to write. After some changes, you can also modify the custom style after you see the code.
The main style control file is Page.css, the bottom of the framework of the paging class can be directly pasted copy use;
1. page.class.php path at the bottom of the frame (Engine\library\think)
In fact, this file does not need to be too much modification, you can also directly use the official line, the following is what I use now, slightly modified;
<?phpnamespace think;class page{public $firstRow;//The Starting line number public $listRows;//list shows the number of rows per page public $parameter;//Paging jump The parameters to be taken public $totalRows; Total number of rows public $totalPages; Total Pages page Public $rollPage = 11;//Page bar The number of pages displayed per page public $lastSuffix = true; Whether the last page shows the total number of pages private $p = ' P '; Paging parameter name private $url = '; Current link URL private $nowPage = 1; Pagination Display custom Private $config = Array (' header ' = ' <span class= ' rows ' >%total_row% records </span> ', ' prev ' = ' << ', ' next ' = ' >> ', ' first ' = ' 1 ... ', ' last ' = ' ...%total_page% ', ' theme ' = > '%first%%up_page%%link_page%%down_page%%end% ',); /** * Schema function * @param array $totalRows total number of records * @param array $listRows number of records per page * @param array $parameter Paging jump parameters */ Public function __construct ($totalRows, $listRows =20, $parameter = Array ()) {C (' var_page ') && $this->p = C (' var_page '); Set paging parameter name/* Basic settings */$this->totalrows = $totalRows; Set total number of records $this-> listRows = $listRows; Set the number of rows to display per page $this->parameter = Empty ($parameter)? $_get: $parameter; $this->nowpage = Empty ($_get[$this->p])? 1:intval ($_get[$this->p]); $this->firstrow = $this->listrows * ($this->nowpage-1); }/** * Custom paging link settings * @param string $name set name * @param string $value Set Value */Public Function setconfig ($name, $value {if (Isset ($this->config[$name])) {$this->config[$name] = $value; }}/** * Generate link URL * @param integer $page page number * @return String */Private function URL ($page) {return STR_REPL Ace (UrlEncode (' [PAGE] '), $page, $this->url); /** * Assemble Paging link * @return String */Public function Show () {if (0 = = $this->totalrows) return '; /* Generate URL */$this->parameter[$this->p] = ' [PAGE] '; $this->url = U (Action_name, $this->parameter); /* Calculate Paging information */$this->totalpages = ceil ($this->totalrows/$this->listrows); Total Pages if (!empty ($this->totalpages) && $this->nowpage > $this->totalpages) {$this->nowpage = $this->totalpages; }/* Calculates the paging zero variable */$now _cool_page = $this->rollpage/2; $now _cool_page_ceil = ceil ($now _cool_page); $this->lastsuffix && $this->config[' last '] = $this->totalpages; Prev $up _row = $this->nowpage-1; $up _page = $up _row > 0? ' <a class= ' prev ' href= '. $this->url ($up _row). ' "rel=" external nofollow ">". $this->config[' prev '). ' </a> ': '; Next $down _row = $this->nowpage + 1; $down _page = ($down _row <= $this->totalpages)? ' <a class= ' next ' href= '. $this->url ($down _row). ' "rel=" external nofollow ">". $this->config[' Next '. ' </a> ': '; The first page $the _first = "; if ($this->totalpages > $this->rollpage && ($this->nowpage-$now _cool_page) >= 1) {$the _first = ' <a class= ' first ' href= '. $this->url (1). ' "rel=" external nofollow ">". $this->config[' first '. ' </a> '; }//Last page $the _end = '; if ($this->totalpages > $this->rollpage && ($this->nowpage + $now _cool_page) < $this TotalPages) {$the _end = ' <a class= ' end ' href= '. $this->url ($this->totalpages). ' "rel=" external nofollow ">". $this->config[' last ']. ' </a> '; }//Digital connection $link _page = ""; for ($i = 1; $i <= $this->rollpage; $i + +) {if ($this->nowpage-$now _cool_page) <= 0) {$page = $i; }elseif (($this->nowpage + $now _cool_page-1) >= $this->totalpages) {$page = $this->totalpages- $this->rollpage + $i; }else{$page = $this->nowpage-$now _cool_page_ceil + $i; if ($page > 0 && $page! = $this->nowpage) {if ($page <= $this->totalpages) {$link _page. = ' <a class= ' num ' href= '. $this->url ($page). ' "rel=" external nofollow ">". $page. ' </a> '; }else{ Break }}else{if ($page > 0 && $this->totalpages! = 1) {$link _page. = ' <span class= ' Curren T ' > '. $page. ' </span> '; }}}//Replace paging content $page _str = str_replace (Array ('%header% ', '%now_page% ', '%up_page% ', '%down_page% ', '%F irst% ', '%link_page% ', '%end% ', '%total_row% ', '%total_page% '), Array ($this->config[' header '), $this->nowpage, $up _page, $down _page, $the _first, $link _page, $the _end, $this->totalrows, $this->totalpages), $this->config [' theme ']); Return "<p>{$page _str}</p>"; }}
2. Controller, write a demo.
Public Function Index () { $obj =m ("News"); $count = $obj->where (' Status=1 and classid=74 ')->count ();//query satisfies the required total number of records $limit = ten; $Page = new \think\page ($count, $limit);//Instantiate the total number of incoming records for the paging class and the number of records displayed per page $show = $Page->show ();//pagination display output $ List = $obj->where (' Status=1 and classid=74 ')->order (' writetime desc ')->limit ($Page->firstrow. ', '. $ page->listrows)->select (); $firstlist = $obj->where (' Status=1 and classid=74 and Indexfirst=1 ')->order (' writetime desc ')->limit (4) Select (); $this->assign (' firstlist ', $firstlist); $this->assign (' page ', $show);//Assignment paging output $this->assign (' list ', $list); $this->display ();}
3. Next is the view layer, style control. PAGE.CSS file
. b-page {background: #fff; box-shadow:0px 1px 2px 0px #E2E2E2;}. page {width:100%; background: #FFF; text-align:center; overflow:hidden; font-size:14px; margin-top:50px;}. Page. First,.page. prev,.page current,.page num,.page current,.page. end {Next,.page 16px; padding:8px 5 px Display:inline-block; Color: #144970; border:1px solid #F2F2F2; border-radius:5px;}. Page. First:hover,.page. prev:hover,.page. Current:hover,.page num:hover,.page. Current:hover,.page. Next:hover. Page. end:hover {text-decoration:none; background: #F8F5F5;}. Page. Current {background-color: #144970; color: #FFF; border-radius:5px;}. Page. current:hover {text-decoration:none; background: #144970;}. Page. not-allowed {cursor:not-allowed;}
Articles you may be interested in:
Example analysis of multi-image upload function implemented by Laravel framework +blob
Swoole 1.10.0 New Release, added a number of new features to resolve
An example of how PHP implements a clockwise print matrix (spiral matrix)