简体   繁体   中英

Yii CListView Pagination customising

is there a way to customise the Yii CListView Pagination object to show

previous 1 of n pages next

rather then

previous 1,2,3 next ?

thanks

You cannot do this by simply passing parameters to the CLinkPager in order to modify its output. So, there is no more elegant method .

But you can very easily override the Pager class by extending CLinkPager and just change the createPageButtons()-Method in the following way:

Yii::import('web.widgets.pagers.CLinkPager');
class YourLinkPager extends CLinkPager{
    /**
 * Creates the page buttons.
 * @return array a list of page buttons (in HTML code).
 */
protected function createPageButtons()
{
    if(($pageCount=$this->getPageCount())<=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_PREVIOUS_PAGE,$currentPage<=0,false);

    /* 
             * !!! change has been made here !!!
             */
    $buttons[]='<li>Page '.$this->getCurrentPage(false).' of '.$this->getPageCount().'</li>';

    // next page
    if(($page=$currentPage+1)>=$pageCount-1)
        $page=$pageCount-1;
    $buttons[]=$this->createPageButton($this->nextPageLabel,$page,self::CSS_NEXT_PAGE,$currentPage>=$pageCount-1,false);

    // last page
    $buttons[]=$this->createPageButton($this->lastPageLabel,$pageCount-1,self::CSS_LAST_PAGE,$currentPage>=$pageCount-1,false);

    return $buttons;
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM