thinkphp pagination class introduction_PHP tutorial
Introduction to thinkphp paging class
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

ThinkPHP6 backend management system development: Implementing backend functions Introduction: With the continuous development of Internet technology and market demand, more and more enterprises and organizations need an efficient, safe, and flexible backend management system to manage business data and conduct operational management. This article will use the ThinkPHP6 framework to demonstrate through examples how to develop a simple but practical backend management system, including basic functions such as permission control, data addition, deletion, modification and query. Environment preparation Before starting, we need to install PHP, MySQL, Com
