设为首页 - 加入收藏 ASP站长网(Aspzz.Cn)- 科技、建站、经验、云计算、5G、大数据,站长网!
热搜: 创业者 手机 数据
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php 重写分页器 CLinkPager的实例(2)

发布时间:2021-03-16 12:16 所属栏目:121 来源:网络整理
导读:/** 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

/**

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

(编辑:ASP站长网)

网友评论
推荐文章
    热点阅读