Yii CListView分页自定义

时间:2012-06-29 09:38:46

标签: php pagination yii

有没有办法自定义Yii CListView Pagination对象来显示

下一页的前1页

而不是

之前的1,2,3下一个?

感谢

2 个答案:

答案 0 :(得分:3)

您不能通过简单地将参数传递给CLinkPager来修改其输出。所以,没有更优雅的方法

但是您可以通过扩展CLinkPager非常轻松地覆盖Pager类,只需按以下方式更改createPageButtons() - Method:

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;
}
}

答案 1 :(得分:0)