thinkphp page-Type source code detailed interpretation (with example interpretation)

Source: Internet
Author: User
Tags prev urlencode

Thinkphp of the page class is very commonly used a class, so particularly detailed look at the source record down to facilitate their own review, here thinkphp is 3.23 version, but no matter which version same, as long as you understand the source code, changed the version will not change the nature.


First of all, the interpretation of the source code, but due to the ability to express the problem may not be so clear.

<?php//+----------------------------------------------------------------------//| thinkphp [WE CAN do it JUST it]//+----------------------------------------------------------------------//|
Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved. // +----------------------------------------------------------------------
// | Licensed (http://www.apache.org/licenses/LICENSE-2.0)//+------------------------------------------------------- ---------------
// | Author: Mai Miao Le <zuojiazi@vip.qq.com>  


The following is an example of the use of interpretation, in fact, I think the example is not so important, it is important to understand the source code, even if there is no instance can be very clear how to use, but in order to more clearly, or here in detail put a few examples.

The following is the pagination page style for the instance:


PHP Code:

<?php
namespace Home\controller;
Use Think\controller;

Class Indexcontroller extends Controller {public
	function index () {
		$page =new \think\page (200,10);
		$page->setconfig (' first ', ' home ');
		$page->setconfig (' prev ', ' prev ');
		$page->setconfig (' Next ', ' next page ');
		$page->lastsuffix=false;//To change the style of the last page, is to set to false, otherwise it will not succeed, the above source has read why this
		$page->setconfig (' Last ', ' End ') );
		$show = $page->show ();
		$this->assign ("page", $show);
		$this->display (' page ');
	}

HTML code:

<! DOCTYPE html>

If you want to change the display format of the page number, here are two examples, one is to remove the end of the display, one is to add total pages of the display:

First of all, to remove the end of the display only need to add this article in the above code:

$page->setconfig (' theme ', '%first%%up_page%%link_page%%down_page% ');

Display as shown in figure:


Here's how to add the total number of pages shown, in fact, only need to $config[' theme '] in the change.

$page->setconfig (' header ', ' <span class= ' rows ' >%now_page%/%total_row% strips </span> ');
$page->setconfig (' theme ', '%first%%up_page%%link_page%%down_page%%end% ');

Above I have made some changes to the display of the total number of pages, showing the following:





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.