What conditions are needed for php pagination?

(*-*)浩
Release: 2023-02-26 20:20:02
Original
3366 people have browsed it

We cannot avoid using the paging function during the project development process. Take PHP as an example. There are many large and small PHP frameworks on the market. Of course, small functions such as paging can be used directly in these frameworks. of.

What conditions are needed for php pagination?

#The paging functions of these frameworks are very convenient to use. Once you configure the parameters required for paging, the results will be available immediately, which is very convenient for developers. But sometimes you will find that these paging functions are not what you expect. (Recommended learning: PHP video tutorial)

Of course we can achieve our needs by modifying the paging of the framework, but it is always limited to the encapsulation of the framework itself, so how do we define ourselves? As for the paging class, now we are required to not only know what it is, but also why it is so.

Okay, so much nonsense, let’s get down to business.

To implement the paging function, you must first know the total number of data items, the number of items displayed on each page, and how many paging numbers are displayed. These three are necessary conditions.

Let’s take a look at the specific implementation first

What conditions are needed for php pagination?

Demonstrate how to write the paging class:

class Mypage{
        private $cur_page;//当前页
        private $total;//总条数
        private $page_size = 10;//每页显示的条数
        private $total_page;//总页数
        private $first_page;//首页显示名称
        private $pre_page;//上一页的显示名称
        private $nex_page;//下一页的显示名称
        private $end_page;//尾页名称
        private $params;//分页后面的筛选参数
        private $num_size = 2;//当前页前后显示几个分页码
        private $base_url;//分页链接地址
        public function __construct(array $page_config=[])
        {
            $this->cur_page = $page_config['cur_page'];
            $this->total = $page_config['total'];
            $this->page_size = $page_config['page_size'];
            $this->base_url = $page_config['base_url'];
            $this->pre_page = isset($page_config['pre_page']) ? $page_config['pre_page'] : "上一页";
            $this->nex_page = isset($page_config['next_page']) ? $page_config['next_page'] : "下一页";
            $this->end_page = isset($page_config['end_page']) ? $page_config['end_page'] : "尾页";
            $this->first_page = isset($page_config['first_page']) ? $page_config['first_page'] : "首页";
            $this->num_size = isset($page_config['num_size']) ? $page_config['num_size'] : 2;
            $this->params = isset($page_config['params']) ?$page_config['params'] : '';
            $this->total_page = ceil($this->total/$this->page_size);
        }
}
Copy after login

The above is the detailed content of What conditions are needed for php pagination?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template