thinkphp Pagination Class Introduction

Source: Internet
Author: User

The pagination class in thinkphp is still very powerful in my opinion, and it is very convenient to use. As long as the total number of bars, and the number of bars displayed per page, as well as the style configuration array, you can easily display pagination, and can easily adjust the front page code style.


Here are some configuration parameters:

Public $firstRow; Number of start lines
Public $listRows; List of rows per page
Public $parameter; Parameters to take when paging jumps
Public $totalRows; Total number of rows
Public $totalPages; Number of page total pages
Public $rollPage = number of pages per page 11;//page bar
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;//Default First page


We generally create new objects as:


$Page=New\think\page($count, -);//Instanced paging class incoming total records and the number of records displayed per page

$show=$Page -Show();//pagination display output

$count is the total number of pages, 25 for each page of records displayed.


The effect of not having any configuration output here is also the default, and we can make some adjustments, such as:

$Page->rollpage = 5 so that it displays up to 5 paging numbers,

$Page->lastsuffix=false;//This parameter is to let his last page not show the total number. Because we can show the total number through the header.


Pagination Display Customization
Private $config = Array (
' Header ' = ' <span class= ' rows ' > Total%total_row% records </span> ',
' Prev ' = ' << ',
' Next ' = ' >> ',
' First ' = ' 1 ... ',
' Last ' = ' ...%total_page% ',
' Theme ' = '%first%%up_page%%link_page%%down_page%%end% ',
);


Here is the default array of page styles, and we can overwrite them by saving new values.

Pass

Public Function Setconfig ($name, $value) {
if (Isset ($this->config[$name])) {
$this->config[$name] = $value;
}
}


This function can be overridden by default, such as theme without HEADER information, we can add%header% to let him show it. The contents of the header can also be overridden by an array of key headers. The other parameters are similar, to illustrate, theme inside we can adjust the position of the header, rather than fixed in front or back, use is very flexible.


Here's a description of how the Thinkphp page class modifies its style through a configuration file.


$page _str = Str_replace (
Array ('%header% ', '%now_page% ', '%up_page% ', '%down_page% ', '%first% ', '%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 ');


This str_replace can be said to be a design essence of the pagination class, first of all the values of the class's properties are assigned separately, finally call this function, read the theme in config to represent the content to be displayed, and the variables in which are replaced by the corresponding array, The implementation of theme in config (which can be a subset of the default theme) controls how pagination and content order is displayed.


Finally, thinkphp will use the previous page, the next page, the first page, the current page all add the default class, so we introduce a CSS file can change his style.




thinkphp Pagination Class Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.