ThinkPHP5 paging function implementation method analysis, thinkphp5 Paging
This article describes how to implement the thinkPHP5 paging function. We will share this with you for your reference. The details are as follows:
In fact, there are not many pages. However, the style issue is quite annoying. So I found the paging class and looked at it. Let's talk about the general structure. If you need to modify the page style, you can modify the style by yourself. It is best to back up data in advance to prevent accidents.
The first is paging call, And tp5 is relatively easy to call.
$ Mod = new \ app \ index \ model \ Blogmsg (); $ mo = $ mod-> paginate (1, 14); $ this-> assign ('LIST ', $ mo); // The rendering template output return $ this-> fetch ('LIST '); // template <div> <ul> {volist name = 'LIST' id = 'user'} <li> {$ user. nickname} </li >{/ volist }</ul> </div >{$ list-> render ()}
The first parameter of the function is the number displayed on each page, and the second parameter is the total number of pages displayed.
(There are 10 pages. If you only write 5 pages, 6-10 pages will not be displayed, but this parameter in the address bar can still be redirected to get the corresponding content ...)
This is the default effect. However, this is only available under the bootstrap template. Specifically named according to the characteristics of bootstrap.
That is to say, in other templates, there are only numbers.
The paging file is located in thinkphp \ library \ think \ paginator.
The driver contains an original paging style. Direct modification is not conducive to later maintenance. Tp5 also provides you with a very convenient modification method. Copy, paste, and rename the source file in the folder. Then change the Bootstrap in class Bootstrap extends Paginator to the file name. Go to config. php and find the page-related configuration.
'type' => 'bootstrap'And change it to your file name. You can call it directly.
I will list several function names that involve styles and briefly describe the meaning of the function.
render()Rendering pagination. Big vernacular is the subject of this paging class.
return sprintf( '<ul class="pagination">%s %s %s</ul>', $this->getPreviousButton(), $this->getLinks(), $this->getNextButton());
The css style is involved here and can be replaced as needed.
The page number itself does not have either the home page or the last page. (But the function provides the value of the last page for you)
You can enter one by yourself. CopygetNextButton()Make relevant modifications.
IngetNextButton()The other two functions are displayed in the function.
getAvailablePageWrapper(url,page)AndgetDisabledTextWrapper($text).
The rendering function just now can be understood as a box, and the two functions can be understood as buttons. You can change the style here. There won't be too many problems.
getLinks()It is in the middle of the pipe. You can see the general meaning of the Code. You can modify the page from these points.