thinkphp 分页类介绍
thinkphp 中的分页类在我看来还是很强大的,使用起来也是很方便的。只要传总的条数,和每页显示的条数,还有样式配置数组,你就可以轻松显示分页,而且可以方便的调整前台页数代码的样式。
下面介绍一下一些配置参数:
public $firstRow; // 起始行数
public $listRows; // 列表每页显示行数
public $parameter; // 分页跳转时要带的参数
public $totalRows; // 总行数
public $totalPages; // 分页总页面数
public $rollPage = 11;// 分页栏每页显示的页数
public $lastSuffix = true; // 最后一页是否显示总页数
private $p = 'p'; //分页参数名
private $url = ''; //当前链接URL
private $nowPage = 1;//默认第一页
我们一般新建对象的时候为:
$Page=new \Think\Page($count,25);// 实例化分页类 传入总记录数和每页显示的记录数(25)
$show= $Page->show();// 分页显示输出
$count 为总的页数,25为每页显示的记录数。
这里没有进行任何配置输出的效果也是默认的,我们可以进行一些调整,比如:
$Page->rollPage = 5,这样就最多显示5个分页数目,
$Page->lastSuffix=false;//这个参数是让他最后一页不显示总的数目。因为我们可以通过header来显示总的数目。
// 分页显示定制
private $config = array(
'header' => '共 %TOTAL_ROW% 条记录',
'prev' => '
'next' => '>>',
'first' => '1...',
'last' => '...%TOTAL_PAGE%',
'theme' => '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%',
);
这里是分页样式默认的数组,我们可以通过攒地新的值来覆盖它们,
通过
public function setConfig($name,$value) {
if(isset($this->config[$name])) {
$this->config[$name] = $value;
}
}
这个函数我们可以把这些默认覆盖,比如theme里面没有header的信息,我们可以加入%HEADER% 来让他显示出来。而header的内容也可以通过一个key为header的数组来覆盖。其他的参数都是类似的,说明一下,theme里面我们可以自己调整header的位置,而不是固定在前面或者后面,用起来很灵活。
下面说明一下,thinkphp这个分页类是如何通过配置文件来修改它的样式的。
$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']);
这个str_replace可以说是分页类的一个设计精华之处,首先前面将类的各个属性的值分开赋值,最后调用这个函数,读取config中的theme来表示要显示的内容,而其中的变量是通过按照对应的数组来替换的,就实现了将config中的theme(可以子集覆盖默认的theme)来控制如何显示分页及内容顺序。
最后就是thinkphp将常用的前一页,后一页,第一页,当前页都加了默认class,所以我们引入一个css文件就可以改变他的样式了。

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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











While installing a new version of an application, Windows may display this error message "An error occurred while parsing C:\\Windows\Microsoft.Net\Framework\v2.0.50727\Config\machine.configParser returned error 0xC00CE556". This problem also occurs when your system boots. No matter what situation you encounter this problem, .NETFramework is the real culprit behind the scenes. There are some very simple fixes you can use to stop this error code from appearing again. Fix 1 – Replace corrupted files You can easily replace corrupted ma from the original directory

[SpringBoot] Passing parameters in the Header through Feign calls How to pass Header parameters through Feign Problem description When we use Feign to request the Api interface of another service in Spring Cloud, there is a need to pass the parameters in the Header. If no special processing is done, it will The parameters in the Header will be lost. Solution 1: Pass it through @RequestHeader(name="headerName"). For example: Feign is defined as follows @FeignClient(name="service-name")pub

The Linux header refers to the beginning of a file or data stream, which is used to contain metadata about the content. By correctly writing and using Header files, developers can better utilize system resources and improve code readability and Maintainability.

Every year before Apple releases a new major version of iOS and macOS, users can download the beta version several months in advance and experience it first. Since the software is used by both the public and developers, Apple has launched developer and public versions, which are public beta versions of the developer beta version, for both. What is the difference between the developer version and the public version of iOS? Literally speaking, the developer version is a developer test version, and the public version is a public test version. The developer version and the public version target different audiences. The developer version is used by Apple for testing by developers. You need an Apple developer account to download and upgrade it.

With the continuous development of the PHP language, ThinkPHP, which is widely used in the PHP back-end framework, is also constantly improving. As business scenarios become increasingly complex, the demand for configuration management in ThinkPHP is also increasing. In this context, ThinkPHP provides rich configuration management functions. Today we will introduce how to implement configuration management through ThinkPHPConfig. 1. Introduction to ThinkPHPConfig ThinkPHPConfig is Thin

How to implement jump in php header: 1. Use "Header("Location:$url");" syntax to implement jump; 2. Use if judgment to implement jump, with jump statements such as "if($_COOKIE[" u_type"]){ header('location:register.php'); } else{ setcookie('u_type','1','86400*360');".

PHP is a powerful programming language that can be used to create dynamic websites and web applications. One of the most powerful features is PHP’s header() method. In this article, we will explore how to use PHP’s header() method to adjust web pages.

Differences: 1. The head tag is used to define the head of the document, which is a container for all head elements, and the header tag is used to define the header (introduction information) of the document; 2. All browsers support the head tag, and older versions of browsers None of the browsers support the header tag, and browsers such as IE9+ and above are required to support the header tag.
