thinkphp Pagination Class Introduction

Source: Internet
Author: User
Tags array config count header

The paging class in thinkphp is still very powerful to me, and it is very convenient to use. As long as you pass the total number of bars, and the number of bars displayed per page, as well as a 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 rows to start
Public $listRows; The list shows the number of rows per page
Public $parameter; Parameters to take when paging jumps
Public $totalRows; Total number of rows
Public $totalPages; Page Total page Count
Public $rollPage = number of pages displayed per page of the 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 typically create new objects by:


$Page =new \think\page ($count, 25);//-Materialized paging class incoming total number of records and number of records displayed per page (25)

$show = $Page->show ()//Paging display output

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


The effect of no configuration output is also default, we can make some adjustments, such as:

$Page->rollpage = 5 so that you can display up to 5 paging numbers,

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


Pagination Display Customization
Private $config = Array (
' Header ' => ' a total of%total_row% records ',
' prev ' => ' << ',
' Next ' => ' >> ',
' => ' 1 ... ',
' Last ' => ' ...%total_page% ',
' Theme ' => '%first%%up_page%%link_page%%down_page% ',
);


This is the default array of pagination 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 allows us to override these defaults, such as theme without HEADER information, and we can join%header% to show it. The header content can also be overridden by an array of key headers. All the other parameters are similar, that is to say, we can adjust the header position in the theme, instead of fixing it in front or back, it is very flexible.


The following is a description of how thinkphp this paging 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 page of the design essence of the class, first of all the properties of the class to assign values separately, and finally call this function, read config in the theme to represent the content to be displayed, and the variables are replaced by the corresponding array, It enables you to control how pagination and content order is displayed by Theme in config (you can override the default theme).


The last is thinkphp will be used in the previous page, the next page, the first page, the current page has been added the default class, so we introduce a CSS file can change his style.






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.