Instructions
Using version: 5.1.35 LTS
A scenario encountered is , the data is an array obtained from the RPC remote call interface, and needs to be displayed on the front-end page.
Solution
You can use the make method of the think\Paginate class to create paginated data. Make method prototype:
/** * @access public * @param $items 需要分页的数据 * @param $listRows 每页数据条数 * @param null $currentPage 当前页数 * @param null $total 总页数 * @param bool $simple 是否使用简单模式(只有上一页和下一页) * @param array $options 其他参数选项,如查询参数,url路径等 * @return Paginator 返回一个分页对象 */ public static function make($items, $listRows, $currentPage = null, $total = null, $simple = false, $options = []) { return new static($items, $listRows, $currentPage, $total, $simple, $options); }
See the code comments for the parameters that need to be passed in.
Since the think\Paginate class is an abstract class, another class needs to inherit it to use its public methods. The think\paginator\driver\Bootstrap class in the framework inherits it, so you can use this class to call the make method.
So, you can write a method to create pagination data from an array, which probably looks like this:
private function getPaginateData($data, $page, $query){ return Bootstrap::make($data, $perPage, $page, $total, false, ['path' => url('module/controller/action'), 'query' => $query]); }
After using this method to generate a paging object, for example: $data = $this->getPaginateData (...), output it to the template in the controller, and then add it to the template page:
{$data|raw}
The template engine will automatically render the paging style.
Recommended tutorial: thinkphp tutorial
The above is the detailed content of Create paginated data using arrays. For more information, please follow other related articles on the PHP Chinese website!

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.

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

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

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

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

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

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

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


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

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.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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

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

SublimeText3 Chinese version
Chinese version, very easy to use