好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > php 重寫分頁器 CLinkPager的實例

php 重寫分頁器 CLinkPager的實例

熱門標簽:商丘外呼系統好處 百度地圖標注類型是酒店 隨州銷售電銷機器人公司 400電話申請辦理 外呼系統人工客服 周口網絡回撥外呼系統 全國各省地圖標注點 福建高頻外呼防封系統哪家好 網絡電話400申請

php 重寫分頁器 CLinkPager的實例

1、自定義的分頁器類放在哪里?

有兩個位置可以放,

第一種是放在 protected/extensions 中,在使用是import進來,或在config文件中import進來;

第二種是放在 protected/components 中,作為組件存在,不需要import

2、用派生方式是最好的

class MyPager extends CLinkPager 

入口函數是:public function run() ,當顯示分頁器時run()被調用,里面的輸出就會顯示在相應位置;

其他的完全自定義,如果你不知道上一頁、下一頁、首頁、尾頁、總頁數、當前頁碼等信息,可以參考CLinkPager的源碼,yii/frameworks/web/widgets/pagers/CLinkPager.php

?php

class MyPager extends CLinkPager
{
  const CSS_FIRST_PAGE='first';
  const CSS_LAST_PAGE='last';
  const CSS_PREVIOUS_PAGE='previous';
  const CSS_NEXT_PAGE='next';
  const CSS_INTERNAL_PAGE='page';
  const CSS_HIDDEN_PAGE='hidden';
  const CSS_SELECTED_PAGE='selected';

  /**
   * @var string the CSS class for the first page button. Defaults to 'first'.
   * @since 1.1.11
   */
  public $firstPageCssClass=self::CSS_FIRST_PAGE;
  /**
   * @var string the CSS class for the last page button. Defaults to 'last'.
   * @since 1.1.11
   */
  public $lastPageCssClass=self::CSS_LAST_PAGE;
  /**
   * @var string the CSS class for the previous page button. Defaults to 'previous'.
   * @since 1.1.11
   */
  public $previousPageCssClass=self::CSS_PREVIOUS_PAGE;
  /**
   * @var string the CSS class for the next page button. Defaults to 'next'.
   * @since 1.1.11
   */
  public $nextPageCssClass=self::CSS_NEXT_PAGE;
  /**
   * @var string the CSS class for the internal page buttons. Defaults to 'page'.
   * @since 1.1.11
   */
  public $internalPageCssClass=self::CSS_INTERNAL_PAGE;
  /**
   * @var string the CSS class for the hidden page buttons. Defaults to 'hidden'.
   * @since 1.1.11
   */
  public $hiddenPageCssClass=self::CSS_HIDDEN_PAGE;
  /**
   * @var string the CSS class for the selected page buttons. Defaults to 'selected'.
   * @since 1.1.11
   */
  public $selectedPageCssClass=self::CSS_SELECTED_PAGE;
  /**
   * @var integer maximum number of page buttons that can be displayed. Defaults to 10.
   */
  public $maxButtonCount=10;
  /**
   * @var string the text label for the next page button. Defaults to 'Next >'.
   */
  public $nextPageLabel;
  /**
   * @var string the text label for the previous page button. Defaults to ' Previous'.
   */
  public $prevPageLabel;
  /**
   * @var string the text label for the first page button. Defaults to ' First'.
   */
  public $firstPageLabel;
  /**
   * @var string the text label for the last page button. Defaults to 'Last >>'.
   */
  public $lastPageLabel;
  /**
   * @var string the text shown before page buttons. Defaults to 'Go to page: '.
   */
  public $header;
  /**
   * @var string the text shown after page buttons.
   */
  public $footer='';
  /**
   * @var mixed the CSS file used for the widget. Defaults to null, meaning
   * using the default CSS file included together with the widget.
   * If false, no CSS file will be used. Otherwise, the specified CSS file
   * will be included when using this widget.
   */
  public $cssFile;
  /**
   * @var array HTML attributes for the pager container tag.
   */
  public $htmlOptions=array();

  /**
   * Initializes the pager by setting some default property values.
   */
  public function init()
  {
    if($this->nextPageLabel===null)
      $this->nextPageLabel=Yii::t('yii','Next >');
    if($this->prevPageLabel===null)
      $this->prevPageLabel=Yii::t('yii',' Previous');
    //if($this->firstPageLabel===null)
    // $this->firstPageLabel=Yii::t('yii',' First');
    //if($this->lastPageLabel===null)
    // $this->lastPageLabel=Yii::t('yii','Last >>');
    if($this->header===null)
      $this->header=Yii::t('yii','Go to page: ');

    if(!isset($this->htmlOptions['id']))
      $this->htmlOptions['id']=$this->getId();
    if(!isset($this->htmlOptions['class']))
      $this->htmlOptions['class']='yiiPager';
  }

  /**
   * Executes the widget.
   * This overrides the parent implementation by displaying the generated page buttons.
   */
  public function run()
  {
    $this->registerClientScript();
    $buttons=$this->createPageButtons();
    if(empty($buttons))
      return;
    echo $this->header;
//   echo CHtml::tag('ul',$this->htmlOptions,implode("\n",$buttons));
    echo implode("\n",$buttons);
    echo $this->footer;
  }

  /**
   * 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,$ellipsis)=$this->getPageRange();

    $currentPage=$this->getCurrentPage(false); // currentPage is calculated in getPageRange()
    $buttons=array();

    // first page
    //$buttons[]=$this->createPageButton($this->firstPageLabel,0,$this->firstPageCssClass,$currentPage=0,false);

    // prev page
    if(($page=$currentPage-1)0)
      $page=0;
    if($currentPage == 0){
      $buttons[] = "span style='background:#a3a3a3'>上一頁/span>";
    }else{
      $buttons[]=$this->createPageButton($this->prevPageLabel,$page,$this->previousPageCssClass,$currentPage=0,false);
    }
    // internal pages start
    // first
    $buttons[]=$this->createPageButton(1,0,$this->internalPageCssClass,false,$i==$currentPage);
    //middle
    if($ellipsis == 'both'){
      $buttons[] = "span style='background:#a3a3a3'>.../span>";
    }
    for($i=$beginPage;$i=$endPage;++$i){
      if($ellipsis == 'left'  $i == $beginPage){
        $buttons[] = "span style='background:#a3a3a3'>.../span>";
      }
      $buttons[]=$this->createPageButton($i+1,$i,$this->internalPageCssClass,false,$i==$currentPage);
      if($ellipsis == 'right'  $i == $endPage){
        $buttons[] = "span style='background:#a3a3a3'>.../span>";
      }
    }  
    if($ellipsis == 'both'){
      $buttons[] = "span style='background:#a3a3a3'>.../span>";
    }
    // last
    $buttons[]=$this->createPageButton($pageCount,$pageCount - 1,$this->internalPageCssClass,false,$i==$currentPage);
    // internal pages end
    // next page
    if(($page=$currentPage+1)>=$pageCount-1)
      $page=$pageCount-1;
    if($currentPage == ($pageCount-1)){
      $buttons[] = "span style='background:#a3a3a3'>下一頁>/span>";
    }else{
      $buttons[]=$this->createPageButton($this->nextPageLabel,$page,$this->nextPageCssClass,$currentPage>=$pageCount-1,false);
    }
    // last page
    //$buttons[]=$this->createPageButton($this->lastPageLabel,$pageCount-1,$this->lastPageCssClass,$currentPage>=$pageCount-1,false);

    return $buttons;
  }

  /**
   * 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,$page,$class,$hidden,$selected)
  {
    if($hidden || $selected)
      $class.=' '.($hidden ? $this->hiddenPageCssClass : $this->selectedPageCssClass);
    if ($selected) {
      $result = "span>" . ++$page . "/span>";
    } 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,$endPage, $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、調用方式

在View里的相應widget,定義pager的class為自定義的分頁器類名即可,參考:

$this->widget('zii.widgets.CListView', array(
  'dataProvider'=>$dataProvider,
  'itemView'=>'_view_t',
  'pager'=>array(
  'class'=>'MyPager',
 )
));

如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

您可能感興趣的文章:
  • thinkPHP實現的驗證碼登錄功能示例
  • thinkPHP實現上傳圖片及生成縮略圖功能示例
  • php+ajax+h5實現圖片上傳功能
  • PHP實現找出數組中出現次數超過數組長度一半的數字算法示例
  • 史上最全的PHP正則表達式(手機號需要加上177-***)
  • PHP用函數嵌入網站訪問量計數器
  • PHP實現網站訪問量計數器
  • 利用php獲得flv視頻長度的實例代碼

標簽:南寧 佛山 迪慶 六安 樂山 十堰 定西 海南

巨人網絡通訊聲明:本文標題《php 重寫分頁器 CLinkPager的實例》,本文關鍵詞  php,重寫,分頁,器,CLinkPager,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《php 重寫分頁器 CLinkPager的實例》相關的同類信息!
  • 本頁收集關于php 重寫分頁器 CLinkPager的實例的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 免费人妻AV无码专区五月| 六月婷婷网视频在线观看| 男人添女人荫蒂视频观看免费| 漂亮美女一级毛片免费| 美国一级毛片oo| 菠萝菠萝蜜在线观看10| 美肉妇臀荡乳欲伦交换H动漫图集 后进式摇摇乳猛烈XXOO小说 | 农村女人一级特黄大片小说| 真人AL亚洲视美女www直播 | 中国老男人同性tv| 爱人体-看人体人体摄影| 婷婷99狠狠躁天天躁中文字幕| 黄金大劫案| 亚洲第一成网站| 把红酒倒入B里喝掉| 美女隐私视频黄www免费| 亚洲1卡2卡三卡3卡4卡网站| 午夜精品一区二区在线观看的 | 国产日韩免费视频| 我要打飞机.com| 禁脔(高h)未| 玉势开男后菊打屁股| 成人无圣光无遮挡全免费漫画| bbwvideos欧美老妇| 美女被网站免费看九色视频| 性bbwbbw日| 小仓优子av| xxxx野外性xxxx| 国产精品1区2区3区在线观看| 正确的性方式和技巧| 91直播app软件下载ios| 久草视频在线播放| 国产成人v视频在线观看| 啊灬啊灬啊灬啊灬高潮了国产精品 | 久青草视频在线| 日本电影巜寂寞人妻| 无码Av免费一区二区三区吻戏| 国产精品素人福利| 欧美Av一区二区三区免费视频| 精产国品一二三产区m553麻豆 | 阿娇被吸得高潮20分钟视频|