YII CLinkPager分页类扩展增加显示共多少页
yii的分页类CLinkPager默认是不支持显示共x页的,那么现在需求来了,要在分页的后面显示共多少页,怎么办喃?我们来看解决办法 1、默认的CLinkPager显示的效果 上面这里写了css的样式哈,我们来看pager代码: widget('CLinkPager',array(
'header' => '','firstPageLabel' => '首页','lastPageLabel' => '尾页','prevPageLabel' => '<','nextPageLabel' => '>','pages' => $pages,'maxButtonCount'=>5,'htmlOptions' => array('class' => 'page-link'),//分页要使用的css样式
));?>
widget('MLinkPager',array(
* 'header' => '',* 'firstPageLabel' => '首页',* 'lastPageLabel' => '尾页',* 'prevPageLabel' => '<',* 'nextPageLabel' => '>',* 'pages' => $pages,* 'maxButtonCount'=>5,* 'htmlOptions' => array('class' => 'page-tab-tog'),* ));?>
*
*/
class MLinkPager extends CLinkPager
{
//设置为true的时候,显示共X页,$this->forceTotalPage值优先该值
public $mCountPage = false;
//是否强制显示共x页,设置为true时,$this->mCountPage和$this->getPageRange()无效
public $forceTotalPage = false;
public function init()
{
}
public function run()
{
$this->registerClientScript();
$buttons=$this->createPageButtons();
list($beginPage,$endPage)=$this->getPageRange();
if ($this->forceTotalPage)
{
$buttons[] = CHtml::tag('li',array('class'=>'totle'),'共'.$this->getPageCount().'页');
}
else
{
if ($this->mCountPage && $endPage > 0)
{
$buttons[] = CHtml::tag('li','共'.$this->getPageCount().'页');
}
}
if(empty($buttons))
return;
echo $this->header;
echo CHtml::tag('div',$this->htmlOptions,implode("n",$buttons));
echo $this->footer;
}
}
|