Video Learning Transcript---thinkphp---TP function class page

Source: Internet
Author: User

(1) Core

Data paging is implemented with the limit syntax

(2) Pagination class

The thinkphp system is packaged with the paging class: Page.class.php

(3) Code Analysis

Location: think/page.class.php,

① View related properties

namespace Think;classpage{
Opening Properties Public $firstRow;//number of start lines Public $listRows;//list shows the number of rows per page limit (start,rows) Public $parameter;//parameters to take when paging jumps Public $totalRows;//total number of rows Public $totalPages;//Total pages per page = number of rows/pages displayed Public $rollPage= 11;//number of pages displayed per page in the page bar (page numbers displayed on the template page) Public $lastSuffix=true;//whether the last page shows the total number of pagesThe following private propertiesPrivate $p= ' P ';//Paging parameter name Private $url= ";//Current Link URL Private $nowPage= 1;
......}

② Page Construction Method: Three parameters, at least pass the first parameter (total number of records), the second parameter is optional (the number of records displayed per page, the default value in the method is 20)

/* Schema function: @param array $totalRows The total number of records, @param array $listRows display the number of records per page; @param array $parameter paging jump parameters*/     Public function__construct ($totalRows,$listRows=20,$parameter=Array()) {C (' Var_page ') &&$this->p = C (' var_page ');//Set paging parameter name        /*Basic Settings*/        $this->totalrows =$totalRows;//set total number of records        $this->listrows =$listRows;//set the number of rows to display per page        $this->parameter =Empty($parameter) ?$_get:$parameter; $this->nowpage =Empty($_get[$this->p])? 1:intval($_get[$this-p]); $this->nowpage =$this->nowpage>0?$this->nowpage:1; $this->firstrow =$this->listrows * ($this->nowpage-1); }

③setconfig method: Use the Config method of the public permission type to set private property $config (page display customization)

④show method: Generate URL links on page numbers and page numbers

Method Summary : The method to be used: The method of construction (used for instantiation), the Setconfig method (used when setting hint text and pagination style), and the Show method (used when generating the URL link of page number and page number)

The analysis is also three methods, the same as the code function (construction method---configuration (you can pass an array, and its member property config to merge, generate a new configuration), check method---Checksum, entry method---output), Other methods (such as encryption verification code, drawing background map, drawing clutter, etc.) are private methods and are not open to the outside.

"Four" to make pagination effect step

Input data Paging-Consult the manual---you can find the TP to achieve data paging there are two ways: ① using the Page class and the Limit method implementation, ② page class and Page method implementation, in the development of the general use of the first method

$User= M (' User ');//instantiating a User object$count=$User->where (' Status=1 ')Count();//the total number of records that the query meets the requirements$Page=New\think\page ($count, 25);//instantiate the total number of incoming records in a paging class and the number of records displayed per page$show=$Page->show ();//Paging display output//Paging data query Note the parameter of the limit method to use the properties of the page class$list=$User->where (' Status=1 ')->order (' Create_time ')->limit ($Page->firstrow. ', '.$Page->listrows)Select ();$this->assign (' list ',$list);//Assignment Data Set$this->assign (' page ',$show);//Assignment Paging output$this->display ();//Output Template

Here is an introduction to the appeal code distribution:

① instantiating the user class build object, connecting the data table

② total number of records queried

③ instantiate paging class, total number of incoming records [number of records displayed per page, default 20 records per page (optional)]

[Optional steps] can only be placed between ③----------④, custom display page tip text Setconfig

④ output page number and page number connection by Show method

⑤ using the Limit method for paged queries, note that the parameter is a property of the page class

⑥ using assign to pass the number of data and paging connections for a query to a template

⑦ Template display

Video Learning Transcript---thinkphp---TP function class page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.