Yii uses the CLinkPager paging instance for details. yiiclinkpager_PHP tutorial

Source: Internet
Author: User
Yii uses the CLinkPager paging instance for details, yiiclinkpager. Yii uses the CLinkPager paging instance for details. yiiclinkpager this article mainly describes how to use the CLinkPager paging method in YII. here we use the object form to define the page: first, use the CLinkPager paging instance in compon Yii, yiiclinkpager

This article mainly explains how to use the CLinkPager paging method in YII. here we use the object form to define the page:

First, you can customize LinkPager in components and inherit the CLinkPager

The code is as follows:

<? Php/*** CLinkPager class file. *** @ link http://www.yiiframework.com/ * @ Copyright Copyright©2008-2011 Yii Software LLC * @ license http://www.yiiframework.com/ License/* // *** CLinkPager displays a list of hyperlinks that lead to different pages of target. ** @ version $ Id $ * @ package system. web. widgets. pagers * @ since 1.0 */class LinkPager extends CLinkPager {const CSS_TOTAL_PAGE = 'total _ page'; const CSS_TOTAL_ROW = 'total _ row '; /*** @ var string the text label for the first page button. ULTS to '<First '. */public $ totalPageLabel;/*** @ var string The text label for the last page button. ULTS to 'last> '. */public $ totalRowLabel;/*** Creates the page buttons. * @ return array a list of page buttons (in HTML code ). */protected function createPageButtons () {$ this-> maxButtonCount = 8; $ this-> firstPageLabel = "homepage"; $ this-> lastPageLabel = 'Last page '; $ this-> nextPageLabel = 'next page'; $ this-> prevPageLabel = 'previous page'; $ this-> header = ""; if ($ pageCount = $ this-> get PageCount () <= 1) return array (); list ($ beginPage, $ endPage) = $ this-> getPageRange (); $ currentPage = $ this-> getCurrentPage (false); // currentPage is calculated in getPageRange () $ buttons = array (); // first page $ buttons [] = $ this-> createPageButton ($ this-> firstPageLabel, 0, self: CSS_FIRST_PAGE, $ currentPage <= 0, false ); // prev page if ($ page = $ currentPage-1) <0) $ page = 0; $ buttons [] = $ this-> createPageButton ($ this-> PrevPageLabel, $ page, self: css_previus_page, $ currentPage <= 0, false); // internal pages for ($ I = $ beginPage; $ I <= $ endPage; + + $ I) $ buttons [] = $ this-> createPageButton ($ I + 1, $ I, self: CSS_INTERNAL_PAGE, false, $ I ==$ currentPage ); // next page if ($ page = $ currentPage + 1) >=$ pageCount-1) $ page = $ pageCount-1; $ buttons [] = $ this-> createPageButton ($ this-> nextPageLabel, $ page, self: CSS_NEXT_PAGE, $ currentPage >=$ pageCount-1, f Alse); // last page $ buttons [] = $ this-> createPageButton ($ this-> lastPageLabel, $ pageCount-1, self: CSS_LAST_PAGE, $ currentPage> = $ pageCount-1, false); // page statistics $ buttons [] = $ this-> createTotalButton ($ currentPage + 1 ). "/{$ pageCount}", self: CSS_TOTAL_PAGE, false, false ); // counts $ buttons [] = $ this-> createTotalButton ("total {$ this-> getItemCount ()}", self: CSS_TOTAL_ROW, false, false ); return $ buttons;} protected function CreateTotalButton ($ label, $ class, $ hidden, $ selected) {if ($ hidden | $ selected) $ class. = ''. ($ hidden? Self: CSS_HIDDEN_PAGE: self: CSS_SELECTED_PAGE); return'
  • '. CHtml: label ($ label, false ).'
  • ';}/*** Registers the needed client scripts (mainly CSS file). */public function registerClientScript () {if ($ this-> cssFile! = False) self: registerCssFile ($ this-> cssFile);}/*** Registers the needed CSS file. * @ param string $ url the css url. if null, a default css url will be used. */public static function registerCssFile ($ url = null) {if ($ url = null) $ url = CHtml: asset (Yii: Optional '); Yii :: app ()-> getClientScript ()-> registerCssFile ($ url );}}

    Define CSS styles

    /***** Flip Style */. page_blue {margin: 3px; padding: 3px; text-align: center; font: 12px verdana, arial, helvetica, sans-serif;} ul. bluePager, ul. yiiPager {font-size: 11px; border: 0; margin: 0; padding: 0; line-height: 100%; display: inline; text-aligin: center;} ul. bluePager li, ul. yiiPager li {display: inline;} ul. bluePager a: link, ul. yiiPager a: link, ul. bluePager a: visited, ul. yiiPager a: visited, ul. bluePager. total _ Page label, ul. yiiPager. total_page label, ul. bluePager. total_row label, ul. yiiPager. total_row label {border: # ddd 1px solid; color: #888888! Important; padding: 2px 5px; text-decoration: none;} ul. bluePager. page a, ul. yiiPager. page a {font-weight: normal;} ul. bluePager a: hover, ul. yiiPager a: hover {color: # FFF! Important; border: # 156a9a 1px solid; background-color: #2b78a3} ul. bluePager. selected a, ul. yiiPager bluePager. selected a {color: #3aa1d0! Important; border: 1px solid #3aa1d0;} ul. bluePager. selected a: hover, ul. yiiPager. selected a: hover {color: # FFF! Important;} ul. bluePager. hidden a, ul. yiiPager. hidden a {border: solid 1px # DEDEDE; color: #888888;} ul. bluePager. hidden, ul. yiiPager. hidden {display: none ;}

    Operations in controller:

    // Paging operation $ criteria = new CDbCriteria; $ criteria-> order = 'Id desc'; $ criteria-> select = array ('id', 'uid ', 'username', 'title', 'thumb', 'URL', 'clicks', 'time', 'Dateline ', 'countfavorite', 'qc '); $ criteria-> condition = $ SQL; $ total = Video: model ()-> count ($ criteria); $ pages = new CPagination ($ total ); $ pages-> pageSize = self: PAGE_SIZE; $ pages-> applyLimit ($ criteria); $ list = Video: model ()-> findAll ($ criteria ); $ title = CommonClass: model ()-> find (array ('select' => array ('cname'), 'condition '=> 'Id = '. $ id,); $ this-> render ('application. views. video. list', array ('array' => $ array, 'arr' => $ arr, 'result' => $ result, 'list' => $ list, 'pages' => $ pages, 'title' => $ title ,));

    Reference in views/video/list. php:

    <?php $this->widget('LinkPager', array('pages' => $pages,)); ?>


    How does yii Framework use warp integration and mysql database for data paging?

    The same is true. The framework just accelerates development efficiency. which step are you getting stuck? specifically, I pasted the code. you cannot learn anything. soon. I forgot to solve it step by step. I remember it ··

    Yii paging problem, urgent

    SQL uses limit and offset. Use $ pages = new CPagination () for paging ();

    This article describes how to use the CLinkPager paging method in YII. here we use the object form to define the page: first in compon...

    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.