The paging class in thinkphp is still very powerful in my opinion and it is also very convenient to use. As long as you pass the total number of items, the number of items displayed on each page, and the style configuration array, you can easily display pagination, and you can easily adjust the style of the front-end page number code.
Here are some configuration parameters:
public $firstRow; // Starting row number
public $listRows; //The number of rows displayed on each page of the list
public $parameter; // Parameters to be taken when pagination jump
public $totalRows; //Total number of rows
public $totalPages; //Total number of paging pages
public $rollPage = 11;//The number of pages displayed on each page of the paging bar
public $lastSuffix = true; // Whether the last page displays the total number of pages
private $p = 'p'; //Paging parameter name
private $url = ''; //Current link URL
private $nowPage = 1; //Default first page
When we usually create a new object:
$Page=new ThinkPage($count,25);// Instantiate the paging class and pass in the total number of records and the number of records displayed on each page (25)
$show= $Page->show();// Display output in pagination
$count is the total number of pages, and 25 is the number of records displayed on each page.
The output effect without any configuration is also the default. We can make some adjustments, such as:
$Page->rollPage = 5, this will display up to 5 page numbers,
$Page->lastSuffix=false;//This parameter prevents the total number from being displayed on the last page. Because we can display the total number through the header.
//Paging display customization
private $config = array(
'header' => 'Total %TOTAL_ROW% records',
'prev' => '
'next' => '>>',
'first' => '1...',
'last' => '...%TOTAL_PAGE%',
'theme' => '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%',
);
Here are the default arrays for pagination styles. We can overwrite them by saving new values,
Passed
public function setConfig($name,$value) {
if(isset($this->config[$name])) {
$this->config[$name] = $value;
}
}
With this function, we can override these defaults. For example, if there is no header information in the theme, we can add %HEADER% to display it. The content of the header can also be overwritten by an array whose key is header. The other parameters are similar. To explain, we can adjust the position of the header ourselves in the theme instead of fixing it in the front or back. It is very flexible to use.
The following explains how the thinkphp paging class modifies its style through the 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 the essence of the design of the paging class. First, the values of each attribute of the class are assigned separately. Finally, this function is called and the theme in the config is read to represent the content to be displayed, and the The variables are replaced according to the corresponding arrays, which enables the theme in the config (the default theme can be overridden by a subset) to control how to display paging and content order.
Finally, thinkphp adds default classes to the commonly used previous page, next page, first page, and current page, so we can change its style by introducing a css file.