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

php 重写分页器 CLinkPager的实例

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

/**

  • Creates a page button.
  • You may override this method to customize the page buttons.
  • @param string $label the text label for the button
  • @param integer $page the page number
  • @param string $class the CSS class for the page button.
  • @param boolean $hidden whether this page button is visible
  • @param boolean $selected whether this page button is selected
  • @return string the generated button
    */
    protected function createPageButton($label,$class,$hidden,$selected)
    {
    if($hidden || $selected)
    $class.=' '.($hidden ? $this->hiddenPageCssClass : $this->selectedPageCssClass);
    if ($selected) {
    $result = "" . ++$page . "";
    } else {
    $result = CHtml::link($label,$this->createPageUrl($page));
    }
    return $result;
    }

/**

  • @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、调用方式

(编辑:核心网)

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

热点阅读