First talk about the paging style of thinkphp3.1 version,Although it looks simple and generous,But all page numbers use simple numbers,The gap between them is relatively small,Not easyAnd the "first 5 pages" and "last 5 pages" are a bit redundant,Because clicking the "Previous" button on the first page of the current display will naturally come out the first 5 pages.

The paging effect of 3.1 is like this:

In view of the above-mentioned less than ideal situations,Coupled with the recent study of thinkphp5, the perfect support for bootstrap pagination style is provided in thinkphp5,As long as the bootstrap.css file is introduced in thinkphp5, after using the paging function in the controller,The front desk will naturally display in the style of bootstrap,The effect is like this:

And I developDingqiuAt the time thinkphp5 had not yet come out,I am using version 3.1, so how can I use bootstrap's paging component in version 3.1?Here is the solution:

1. Derive thinkphp's native page.class.php class

In order not to affect the core file (in violation of the design modification kind of closure principle), I derived a subclass listpage, the code of this subclass is as follows:

import ("org.util.page");//Import the paging class
 class listpage extends page
 {//Rewrite related functions in the page class for the characteristics of the user controller of this system
   * Pagination display output
   * @access public
   * /
  protected $config=array ("header" =>"records", "prev" =>"<", "next" =>">",  "first" =>"<<", "last" =>">>",  "theme" =>"%first%%uppage%%linkpage%%downpage%%end%");

can be seen,First import the file where the core class is located,Then you can derive it boldly,Only the core code is listed here.We just need to modify the config variable in the page class.Rewrite the variable in the subclass as above,Then use this subclass in all actions (controllers) to create a paging object:

$page=new listpage ($count, 5);

This way we can use our settings above,OK, here's the result:

  • Previous Simple example of AngularJS ng-controller directive
  • Next jQuery ajax and traversing array json instance code