Table of Contents
ThinkPHP paging implementation, thinkphp paging implementation
How to implement paging and email sending in thinkphp
thinkphp data paging (article paging)
Home Backend Development PHP Tutorial ThinkPHP paging implementation, thinkphp paging implementation_PHP tutorial

ThinkPHP paging implementation, thinkphp paging implementation_PHP tutorial

Jul 13, 2016 am 10:17 AM
thinkphp

ThinkPHP paging implementation, thinkphp paging implementation

TP3.2 framework manual, there is a data paging, but you have to write too much code every time, and there are some Chinese settings, etc. Sorry, as a program developer, I need to sort it out:

O. Let’s look at the renderings first

1. Paging method

<span>/*</span><span>*
 * TODO 基础分页的相同代码封装,使前台的代码更少
 * @param $m 模型,引用传递
 * @param $where 查询条件
 * @param int $pagesize 每页查询条数
 * @return \Think\Page
 </span><span>*/</span>
<span>function</span> getpage(&<span>$m</span>,<span>$where</span>,<span>$pagesize</span>=10<span>){
    </span><span>$m1</span>=<span>clone</span> <span>$m</span>;<span>//</span><span>浅复制一个模型</span>
    <span>$count</span> = <span>$m</span>->where(<span>$where</span>)-><span>count</span>();<span>//</span><span>连惯操作后会对join等操作进行重置</span>
    <span>$m</span>=<span>$m1</span>;<span>//</span><span>为保持在为定的连惯操作,浅复制一个模型</span>
    <span>$p</span>=<span>new</span> Think\Page(<span>$count</span>,<span>$pagesize</span><span>);
    </span><span>$p</span>->lastSuffix=<span>false</span><span>;
    </span><span>$p</span>->setConfig('header','<li class="rows">共<b>%TOTAL_ROW%</b>条记录  每页<b>%LIST_ROW%</b>条  第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>'<span>);
    </span><span>$p</span>->setConfig('prev','上一页'<span>);
    </span><span>$p</span>->setConfig('next','下一页'<span>);
    </span><span>$p</span>->setConfig('last','末页'<span>);
    </span><span>$p</span>->setConfig('first','首页'<span>);
    </span><span>$p</span>->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'<span>);

    </span><span>$p</span>->parameter=I('get.'<span>);

    </span><span>$m</span>->limit(<span>$p</span>->firstRow,<span>$p</span>-><span>listRows);

    </span><span>return</span> <span>$p</span><span>;
}</span>
Copy after login

The getpage method can be placed in Application/Common/Common/function.php of the TP framework. This document can specifically place some common methods, which can be called anywhere (such as: Controller files, View files, etc.).

2. Call the paging method

<span>$m</span>=M('products'<span>);
</span><span>$p</span>=getpage(<span>$m</span>,<span>$where</span>,10<span>);
</span><span>$list</span>=<span>$m</span>->field(<span>true</span>)->where(<span>$where</span>)->order('id desc')-><span>select();
</span><span>$this</span>-><span>list</span>=<span>$list</span><span>;
</span><span>$this</span>->page=<span>$p</span>->show();
Copy after login

View code again

<div class="pagination"><span>
  {$page}
</div></span>
Copy after login

Third, the last step is the paging style. This is a bit messy. Because the background framework is downloaded from the Internet, the style has not yet been sorted out. This style can also be implemented by yourself, it is simple.

<span>.pagination ul </span>{<span>
    display</span>:<span> inline-block</span>;<span>
    margin-bottom</span>:<span> 0</span>;<span>
    margin-left</span>:<span> 0</span>;<span>
    -webkit-border-radius</span>:<span> 3px</span>;<span>
    -moz-border-radius</span>:<span> 3px</span>;<span>
    border-radius</span>:<span> 3px</span>;<span>
    -webkit-box-shadow</span>:<span> 0 1px 2px rgba(0,0,0,0.05)</span>;<span>
    -moz-box-shadow</span>:<span> 0 1px 2px rgba(0,0,0,0.05)</span>;<span>
    box-shadow</span>:<span> 0 1px 2px rgba(0,0,0,0.05)</span>;
}<span>
.pagination ul li </span>{<span>
  display</span>:<span> inline</span>;
}<span>

.pagination ul li.rows </span>{<span>
    line-height</span>:<span> 30px</span>;<span>
    padding-left</span>:<span> 5px</span>;
}<span>
.pagination ul li.rows b</span>{<span>color</span>:<span> #f00</span>}<span>

.pagination ul li a, .pagination ul li span </span>{<span>
    float</span>:<span> left</span>;<span>
    padding</span>:<span> 4px 12px</span>;<span>
    line-height</span>:<span> 20px</span>;<span>
    text-decoration</span>:<span> none</span>;<span>
    background-color</span>:<span> #fff</span>;<span>
    background</span>:<span> url('../images/bottom_bg.png') 0px 0px</span>;<span>
    border</span>:<span> 1px solid #d3dbde</span>;
    <span>/*</span><span>border-left-width: 0;</span><span>*/</span><span>
    margin-left</span>:<span> 2px</span>;<span>
    color</span>:<span> #08c</span>;
}<span>
.pagination ul li a:hover</span>{<span>
    color</span>:<span> red</span>;<span>
    background</span>:<span> #0088cc</span>;
}<span>
.pagination ul li.first-child a, .pagination ul li.first-child span </span>{<span>
    border-left-width</span>:<span> 1px</span>;<span>
    -webkit-border-bottom-left-radius</span>:<span> 3px</span>;<span>
    border-bottom-left-radius</span>:<span> 3px</span>;<span>
    -webkit-border-top-left-radius</span>:<span> 3px</span>;<span>
    border-top-left-radius</span>:<span> 3px</span>;<span>
    -moz-border-radius-bottomleft</span>:<span> 3px</span>;<span>
    -moz-border-radius-topleft</span>:<span> 3px</span>;
}<span>
.pagination ul .disabled span, .pagination ul .disabled a, .pagination ul .disabled a:hover </span>{<span>
color</span>:<span> #999</span>;<span>
cursor</span>:<span> default</span>;<span>
background-color</span>:<span> transparent</span>;
}<span>
.pagination ul .active a, .pagination ul .active span </span>{<span>
color</span>:<span> #999</span>;<span>
cursor</span>:<span> default</span>;
}<span>
.pagination ul li a:hover, .pagination ul .active a, .pagination ul .active span </span>{<span>
background-color</span>:<span> #f0c040</span>;
}<span>
.pagination ul li.last-child a, .pagination ul li.last-child span </span>{<span>
    -webkit-border-top-right-radius</span>:<span> 3px</span>;<span>
    border-top-right-radius</span>:<span> 3px</span>;<span>
    -webkit-border-bottom-right-radius</span>:<span> 3px</span>;<span>
    border-bottom-right-radius</span>:<span> 3px</span>;<span>
    -moz-border-radius-topright</span>:<span> 3px</span>;<span>
    -moz-border-radius-bottomright</span>:<span> 3px</span>;
}<span>

.pagination ul li.current a</span>{<span>color</span>:<span> #f00 </span>;<span>font-weight</span>:<span> bold</span>;<span> background</span>:<span> #ddd</span>}
Copy after login

How to implement paging and email sending in thinkphp

TP’s paging is actually very simple:
First you need to import the paging class.
The code is as follows:

$User = M('User'); // Instantiate the User object
import('ORG.Util.Page');//Import the paging class
$count = $User->where('status=1')->count();// Query the total number of records that meet the requirements
$Page = new Page($count,25);// Example Pass in the total number of records and the number of records displayed on each page to the paging class
$show = $Page->show(); // Paging display output
// When performing paging data query, pay attention to the parameters of the limit method. Use the attributes of the Page class
$list = $User->where('status=1')->order('create_time')->limit($Page->firstRow.','.$ Page->listRows)->select();
$this->assign('list',$list);//Assign data set
$this->assign('page', $show);// Assignment paging output
$this->display(); // Output template

thinkphp data paging (article paging)

Article pagination, I remember there should be thinkphpcms. Find that one, install it and see how it is written. . You can do it - -

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/893202.htmlTechArticleThinkPHP paging implementation, thinkphp paging implementation TP3.2 framework manual, there is a data paging, but you have to write it every time Too many codes, and Chinese settings are a bit troublesome. As a program development...
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

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

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

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.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

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.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

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.

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

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.

Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Nov 22, 2023 pm 12:01 PM

"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.

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

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.

How is the performance of thinkphp? How is the performance of thinkphp? Apr 09, 2024 pm 05:24 PM

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.

Development suggestions: How to use the ThinkPHP framework for API development Development suggestions: How to use the ThinkPHP framework for API development Nov 22, 2023 pm 05:18 PM

Development suggestions: How to use the ThinkPHP framework for API development. With the continuous development of the Internet, the importance of API (Application Programming Interface) has become increasingly prominent. API is a bridge for communication between different applications. It can realize data sharing, function calling and other operations, and provides developers with a relatively simple and fast development method. As an excellent PHP development framework, the ThinkPHP framework is efficient, scalable and easy to use.

See all articles