Yii Paging Component Usage case analysis, yii pagination example Analysis _php tutorial

Source: Internet
Author: User

Yii Paging Component Usage example analysis, Yii paging instance analysis


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 $config =array (' Headers ' and ' Records ', ' prev ' and ' prev ', ' next ' = ' next ', ' first ' = ' home ', ' last ' + ' 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 ''; } function Fpage ($display =array (0,1,2,3,4,5,6,7,8)) {$html [0]=] Total{$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.

Articles you may be interested in:

    • Yii method to get the current URL and domain name
    • A summary of URL production problems in Yii framework
    • An example analysis of writing method for Yii extension component
    • Analysis of Assetmanager principle of yii core component
    • Yii uses URL components to beautify the management method

http://www.bkjia.com/PHPjc/1085891.html www.bkjia.com true http://www.bkjia.com/PHPjc/1085891.html techarticle Yii Paging Component Usage example analysis, Yii paging instance analysis This article describes the Yii paging component usage. Share to everyone for your reference, as follows: When the case is used, pagination class ...

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