[英]Yii CListView Pagination customising
有沒有一種方法可以自定義Yii CListView分頁對象以顯示
前1頁,共n頁下一頁
而不是
上一個1,2,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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.