加入收藏 | 设为首页 | 会员中心 | 我要投稿 网站开发网_马鞍山站长网 (https://www.0555zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长百科 > 正文

php 重写分页器 CLinkPager的实例

发布时间:2021-03-18 12:07:35 所属栏目:站长百科 来源:网络整理
导读:副标题#e# php 重写分页器 CLinkPager的实例 1、自定义的分页器类放在哪里? 有两个位置可以放, 第一种是放在 protected/extensions 中,在使用是import进来,或在config文件中import进来; 第二种是放在 protected/components 中,作为组件存在,不需要im

@return array the begin and end pages that need to be displayed.
/
protected function getPageRange()
{
$currentPage=$this->getCurrentPage();
$pageCount=$this->getPageCount();
/
$beginPage=max(0,$currentPage-(int)($this->maxButtonCount/2));
if(($endPage=$beginPage+$this->maxButtonCount-1)>=$pageCount)
{
$endPage=$pageCount-1;
$beginPage=max(0,$endPage-$this->maxButtonCount+1);
}*/
if($pageCount > $this->maxButtonCount){
if($currentPage > 4 && $currentPage < ($pageCount - 4)){
// print_r('a');
$beginPage = $currentPage - 2;
$endPage = $currentPage + 2;
$ellipsis = 'both';
}else{
$beginPage=max(1,$currentPage-(int)($this->maxButtonCount/2));
if($beginPage == 1){
$ellipsis = 'right';
}else{
$ellipsis = 'left';
}
if(($endPage=$beginPage+$this->maxButtonCount-1)>=$pageCount)
{
// print_r('b');
$endPage=$pageCount-2;
$beginPage=max(1,$endPage-$this->maxButtonCount+1);
}elseif(($endPage=$beginPage+$this->maxButtonCount-1)>=$pageCount-2){
// print_r('c');
$endPage=$pageCount-2;
}

}
}else{
$beginPage=max(1,$currentPage-(int)($this->maxButtonCount/2));
if(($endPage=$beginPage+$this->maxButtonCount-1)>=$pageCount)
{
$endPage=$pageCount-2;
$beginPage=max(1,$endPage-$this->maxButtonCount+1);
}
}

return array($beginPage,$ellipsis);

}

/**

  • 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::getPathOfAlias('system.web.widgets.pagers.pager').'.css');
    Yii::app()->getClientScript()->registerCssFile($url);
    }
    }

3、调用方式

(编辑:网站开发网_马鞍山站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!