search
HomePHP FrameworkThinkPHPHow to paginate in thinkphp5

How to paginate in thinkphp5

Aug 23, 2019 pm 01:20 PM
thinkphp5Pagination

How to paginate in thinkphp5

In fact, the content of the paging itself is not very much. However, it seems quite annoying when it comes to style issues. So I found the paging class and took a look. Let’s talk about the general structure. If you need to modify the page style, you can modify the style yourself. It is best to back up in advance to prevent accidents.

The first is the paging call. It is relatively easy to call tp5:

$mod = new \app\index\model\Blogmsg();
$mo = $mod->paginate(1,14);
$this->assign('list', $mo);
// 渲染模板输出
return $this->fetch('list');
//模板方面
<div>
<ul>
{volist name=&#39;list&#39; id=&#39;user&#39;}
<li> {$user.nickname}</li>
{/volist}
</ul>
</div>
{$list->render()}

The first parameter of the function is how many pages are displayed on each page, and the second parameter is how many pages are displayed in total.

Related recommendations: "ThinkPHP Tutorial"

(Originally there are 10 pages, and you only write 5 pages, then pages 6-10 will not be displayed, but the address You can still jump to this parameter to get the corresponding content)

How to paginate in thinkphp5

The default is this effect. But this is an effect only available under the bootstrap template. Named specifically based on the characteristics of bootstrap.

In other words, under other templates, it is just a simple number.

The location of the pagination file is in thinkphp\library\think\paginator.
There is a paging style original version in the driver. Direct modification is not conducive to later maintenance. And tp5 also gives you a very convenient modification method. Copy and paste the source files in the folder and rename them. Then change the word "Bootstrap" in class Bootstrap extends Paginator to the name of the file. Then go to config.php to find the paging-related configuration.

'type' => 'bootstrap', change it to your file name. You can call it directly.

I will list several function names involved in styles and briefly talk about the meaning of existence.

render() renders paging, and the vernacular is the main body of this paging class.

return sprintf(
  &#39;<ul class="pagination">%s %s %s</ul>&#39;,
  $this->getPreviousButton(),
  $this->getLinks(),
  $this->getNextButton()
);

This involves the css style, which can be replaced according to your own needs.

The page number itself has no first and last page items. (But the function provides you with the value of the last page)
You can fill it in yourself. Just copy getNextButton() and make relevant modifications.

You will see two other functions in the getNextButton() function:

getAvailablePageWrapper(url,page) and getDisabledTextWrapper($text).

The rendering function just now can be understood as a box, and these two functions can be understood as buttons. If you want to change the style, just do it here. Anyone who can do this won't have much of a problem.

getLinks() is in the middle. You can basically tell the general meaning by looking at the code. You can basically start from these places to modify paging.

The above is the detailed content of How to paginate in thinkphp5. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What Are the Key Features of ThinkPHP's Built-in Testing Framework?What Are the Key Features of ThinkPHP's Built-in Testing Framework?Mar 18, 2025 pm 05:01 PM

The article discusses ThinkPHP's built-in testing framework, highlighting its key features like unit and integration testing, and how it enhances application reliability through early bug detection and improved code quality.

How to Use ThinkPHP for Building Real-Time Stock Market Data Feeds?How to Use ThinkPHP for Building Real-Time Stock Market Data Feeds?Mar 18, 2025 pm 04:57 PM

Article discusses using ThinkPHP for real-time stock market data feeds, focusing on setup, data accuracy, optimization, and security measures.

What Are the Key Considerations for Using ThinkPHP in a Serverless Architecture?What Are the Key Considerations for Using ThinkPHP in a Serverless Architecture?Mar 18, 2025 pm 04:54 PM

The article discusses key considerations for using ThinkPHP in serverless architectures, focusing on performance optimization, stateless design, and security. It highlights benefits like cost efficiency and scalability, but also addresses challenges

How to Implement Service Discovery and Load Balancing in ThinkPHP Microservices?How to Implement Service Discovery and Load Balancing in ThinkPHP Microservices?Mar 18, 2025 pm 04:51 PM

The article discusses implementing service discovery and load balancing in ThinkPHP microservices, focusing on setup, best practices, integration methods, and recommended tools.[159 characters]

What Are the Advanced Features of ThinkPHP's Dependency Injection Container?What Are the Advanced Features of ThinkPHP's Dependency Injection Container?Mar 18, 2025 pm 04:50 PM

ThinkPHP's IoC container offers advanced features like lazy loading, contextual binding, and method injection for efficient dependency management in PHP apps.Character count: 159

How to Use ThinkPHP for Building Real-Time Collaboration Tools?How to Use ThinkPHP for Building Real-Time Collaboration Tools?Mar 18, 2025 pm 04:49 PM

The article discusses using ThinkPHP to build real-time collaboration tools, focusing on setup, WebSocket integration, and security best practices.

What Are the Key Benefits of Using ThinkPHP for Building SaaS Applications?What Are the Key Benefits of Using ThinkPHP for Building SaaS Applications?Mar 18, 2025 pm 04:46 PM

ThinkPHP benefits SaaS apps with its lightweight design, MVC architecture, and extensibility. It enhances scalability, speeds development, and improves security through various features.

How to Build a Distributed Task Queue System with ThinkPHP and RabbitMQ?How to Build a Distributed Task Queue System with ThinkPHP and RabbitMQ?Mar 18, 2025 pm 04:45 PM

The article outlines building a distributed task queue system using ThinkPHP and RabbitMQ, focusing on installation, configuration, task management, and scalability. Key issues include ensuring high availability, avoiding common pitfalls like imprope

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor