Yii paging component usage instance analysis, yii paging instance Analysis _ PHP Tutorial

Source: Internet
Author: User
Yii paging component usage instance analysis, yii paging instance analysis. Yii paging component usage example analysis, yii paging instance analysis this article describes the yii paging component usage. This article is for your reference. for details, refer to the usage of the yii paging component and yii paging instance in this case.

This example describes the usage of the yii paging component. We will share this with you for your reference. The details are as follows:

In this case, the paging class exists in components in the form of components in the yii Framework.

The action code is as follows:

Public function actionIndex () {$ user = User: model (); // use $ count = $ user-> count () for paging (); // obtain the total number of pages $ pagesize = 3; // The number of records displayed on each page $ 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, retrieve information by traversing info and output show_page to display the page List and other information.

The page. php code is attached as follows:

<? Php/*** paging class, which exists in the componnets file as a component */class Page {private $ total; // total number of records in the data table private $ listRows; // The number of rows displayed on each page is private $ limit; private $ uri; private $ pageNum; // The number of pages is private $ config = array ('header' => "records ", "prev" => "previous page", "next" => "next page", "first" => "first page", "last" => "last page "); 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-> 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, 2, 3, 4, 5, 6, 7, 8) {$ html [0] = "total{$ This-> total}{$ This-> config ["header"]} "; $ html [1] =" displayed on each page". ($ This-> end ()-$ this-> start () + 1 ).", This page{$ This-> start ()}-{$ this-> end ()}"; $ 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 ;}}

I hope this article will help you design PHP programs based on the yii Framework.

Articles you may be interested in:
  • Yii method for obtaining the current url and domain name
  • Summary of Url production issues in the yii Framework
  • Yii extension component writing method instance analysis
  • Principle analysis of AssetManager, Yii core component
  • How to beautify YII by using url components

In this example, the usage of the yii paging component is described. I will share it with you for your reference as follows: in this case, the paging 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.