Analysis of usage examples of yii paging component

Source: Internet
Author: User
The examples in this article describe the usage of yii paging components. Share to everyone for your reference, as follows:

When this case is used, the paging class exists as a component in the YII framework in the form of components.

The action code is as follows:

Public Function Actionindex () {  $user =user::model ();  Use of paging  $count = $user->count ();//Get  The total number of pages $pagesize = 3;//each page displays a record strip  $page =new page ($count, $pagesize);  $sql = "Select * from {{user}} $page->limit";  $info = $user->findallbysql ($sql);  $show _page= $page->fpage ();  $this->renderpartial ("index", Array ("info" = = $info, ' show_page ' = $show _page));}

On the view page, you can traverse info to get information, and output show_page to display a list of pages.

We enclose the page.php code as follows:

<?php/** * Pagination class, in the form of components in the Componnets file */class page {private $total;//The total number of records in the data table private $listRows;//page shows the number of rows private $  Limit  Private $uri; Private $pageNum;  Pages private $c "prev" and "prev", "Next" = "Next", "first" = "Home", "last" and "End");  Private $listNum = 8;   /* * $total * $listRows * * Public function __construct ($total, $listRows =10, $pa = "") {$this->total= $total;   $this->listrows= $listRows;   $this->uri= $this->geturi ($PA); $this->page=!empty ($_get["page"])?   $_get["Page"]: 1;   $this->pagenum=ceil ($this->total/$this->listrows);  $this->limit= $this->setlimit (); } Private Function Setlimit () {return ' Limit '.  $this->page-1) * $this->listrows. ", {$this->listrows}"; } Private Function GetURI ($PA) {$url =$_server["Request_uri"]. ( Strpos ($_server["Request_uri"], '? ')? ': '? ').   $PA;   $parse =parse_url ($url);    if (Isset ($parse ["Query"])) {parse_str ($parse [' query '], $params);    unset ($params ["page"]); $url = $parse [' PatH ']. '? '.   Http_build_query ($params);  } return $url;   } function __get ($args) {if ($args = = "Limit") return $this->limit;  else return null;   } Private Function Start () {if ($this->total==0) return 0;  else return ($this->page-1) * $this->listrows+1;  } Private Function End () {return min ($this->page* $this->listrows, $this->total);   } Private Function First () {$html = ';   if ($this->page==1) $html. = ';   else $html. = "Uri}&page=1 ' >{$this->config[" First "]}";  return $html;   } Private Function Prev () {$html = ';   if ($this->page==1) $html. = '; else $html. = "Uri}&page=". ($this->page-1). "'   >{$this->config["prev"} ";  return $html;   } Private Function PageList () {$linkPage = "";   $inum =floor ($this-&GT;LISTNUM/2);    for ($i = $inum; $i >=1; $i-) {$page = $this->page-$i;    if ($page <1) continue;   $linkPage. = "uri}&page={$page} ' >{$page}";   } $linkPage. = "{$this->page}";for ($i =1; $i <= $inum; $i + +) {$page = $this->page+ $i;    if ($page <= $this->pagenum) $linkPage. = "uri}&page={$page} ' >{$page}";   else break;  } return $linkPage;   } Private Function Next () {$html = ';   if ($this->page== $this->pagenum) $html. = "; else $html. = "Uri}&page=". ($this->page+1). "'   >{$this->config["Next"} ";  return $html;   } private Function Last () {$html = ';   if ($this->page== $this->pagenum) $html. = "; else $html. = "Uri}&page=". ($this->pagenum). "'   >{$this->config["Last"]} ";  return $html;  } Private Function Gopage () {return '{$this->total}{$this->config["header"]}   "; $html [1]=] Display per page". ($this->end ()-$this->start () +1). "Bar, this page{$this->start ()}-{$this->end ()}Article "; $html [2]=]{$this->page}/{$this->pagenum}Page ";   $html [3]= $this->first ();   $html [4]= $this->prev ();   $html [5]= $this->pagelist ();   $html [6]= $this->next ();   $html [7]= $this->last ();   $html [8]= $this->gopage ();   $fpage = ";   foreach ($display as $index) {$fpage. = $html [$index];  } return $fpage; }}

It is hoped that this article is helpful to the PHP program design based on YII framework.

The above describes the Yii page component Usage example analysis, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.