thinkphp Pagination class Use detailed

Source: Internet
Author: User
Tags foreach php class

  When the content of the Web site is more and more, the application of paging function came into being, this article we will focus on the next thinkphp framework from the page class calls

First, we need to add a Msgmanage controller   knowledge Points: 1, the Count function of the Trial 2, page class instantiation operation and related parameters to understand the 3, limit function with 4, show function to understand   edit file admin/lib/ action/msgmanageaction.class.php   Code as follows:   Code as follows: Class Msgmanageaction extends Commonaction {    publ IC function Index () {     import (' ORG. Util.page ');  //import calls the Page.class.php class file       $count in the expansion pack extend/library/org/util/under the message/thinkphp framework directory = M (' board ')->count ();  //Call Board Library, remove all data bars       $page = new page ($count, 10);  //Instantiate the page class, where the first argument is the total number of display bars, 10 at a time, which is the value of the following $page->listrows   $limit = $page->firstrow. ',' . $page->listrows;  //$page->firstrow is the number of starting bars to find, the default is 0, if $page->listrows is 10, then the 2nd page $page->firstrow is 10, and so on     $ board = M (' board ')->order (' Time DESC ')->limit ($limit)->select ();  /Note that the->limit ($limit)   $this->board = $board is added here compared to the previous version.   $this->page = $page->show ();  //Will $page->show () through the Show method to resolve the $pageDisplays and assigns to the template variable for template invocation     $this->display ();    }    public function Delete () {  $id = I (' id ', ', ', ' intval ');     if (M (' board ')->d Elete ($id)) {    $this->success (' delete Success ', U (' index '))  }else{    $this->error (' delete failed '); nbsp The &nbsp}     Show method is a new feature that is available in version 3.1 thinkphp the process of page output is to read the template file and then parse the template (which also supports invoking Third-party template engine parsing), but in some cases we do not have a template file defined. Or to save the template file in the database, so this time for the page output, we are unable to read the template file, the 3.1 version of this situation to increase the content of the output of the function of parsing. The built-in template engine is also improved, and if the incoming template file does not exist, it is considered the incoming template parsing content, so the view class and the action class for 3.1 also make some improvements. The display method is used for the template file render output, and the Show method is used for the template content rendering output, and the Show method still supports the content parsing function specific contents may refer to: ThinkPHP3.1 new characteristic content analytic output Two, adds the paging module in the template file The knowledge point: 1, TD Cell Merge 2, $page variable call display   Edit file: admin/tpl/msgmanage/index.html, add a section of TR to display paging related, the code is as follows:     code is as follows: <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "> <title>mesSage Board background</title> </head> <body>  <table class= "table" border= "1" >   < tr>    <th>ID</th>    <th> publisher </th>    <th> content </th >    <th> release time </th>    <th> operation </th>   </tr>     < foreach name= ' board ' item= ' B ' >    <tr>     <td>{$b .id}</td>     < td>{$b .username}</td>     <td>{$b .content}</td>     <td>{$b. time|date = ' y-m-d h:i ',###}</td>     <td><a href= ' {: U (' Admin.php/msgmanage/delete ', array (' ID ' => $b [' ID ']], ' > Delete </a></td>    </tr>   </foreach>    //Add TR code Short   <tr>    <TD colspan= ' 5 ' align= ' center ' >    //merges 5 cells and centers the     {$page }    //Display controller $this->page content    </TD&GT   </tr>  </table> </body> </html>
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.