欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Yii使用CLinkPager分頁實例詳解

 更新時間:2014年07月23日 09:32:20   投稿:shichen2014  
這篇文章主要介紹了Yii使用CLinkPager分頁的方法,需要的朋友可以參考下

本文主要講解了YII中使用CLinkPager分頁的方法,這里我們采用物件的形式來定義分頁:

首先在components中自定義LinkPager,并繼承CLinkPager

具體代碼如下:

<?php
/**
 * CLinkPager class file.
 *
 * @link http://www.yiiframework.com/
 * @copyright Copyright © 2008-2011 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

/**
 * CLinkPager displays a list of hyperlinks that lead to different pages of target.
 *
 * @version $Id$
 * @package system.web.widgets.pagers
 * @since 1.0
 */
class LinkPager extends CLinkPager
{
 const CSS_TOTAL_PAGE='total_page';
 const CSS_TOTAL_ROW='total_row';
 
 /**
 * @var string the text label for the first page button. Defaults to '<< First'.
 */
 public $totalPageLabel;
 /**
 * @var string the text label for the last page button. Defaults to 'Last >>'.
 */
 public $totalRowLabel;
 
 /**
 * Creates the page buttons.
 * @return array a list of page buttons (in HTML code).
 */
 protected function createPageButtons()
 {
 

    $this->maxButtonCount=8; 
    $this->firstPageLabel="首頁";
    $this->lastPageLabel='末頁'; 
    $this->nextPageLabel='下一頁';
    $this->prevPageLabel='上一頁'; 
    $this->header="";
 
 if(($pageCount=$this->getPageCount())<=1)
  return array();
 
 list($beginPage,$endPage)=$this->getPageRange();
 $currentPage=$this->getCurrentPage(false); // currentPage is calculated in getPageRange()
 $buttons=array();
 
 // first page
 $buttons[]=$this->createPageButton($this->firstPageLabel,0,self::CSS_FIRST_PAGE,$currentPage<=0,false);

 // prev page
 if(($page=$currentPage-1)<0)
  $page=0;
 $buttons[]=$this->createPageButton($this->prevPageLabel,$page,self::CSS_PREVIOUS_PAGE,$currentPage<=0,false);

 // internal pages
 for($i=$beginPage;$i<=$endPage;++$i)
  $buttons[]=$this->createPageButton($i+1,$i,self::CSS_INTERNAL_PAGE,false,$i==$currentPage);

 // next page
 if(($page=$currentPage+1)>=$pageCount-1)
  $page=$pageCount-1;
 $buttons[]=$this->createPageButton($this->nextPageLabel,$page,self::CSS_NEXT_PAGE,$currentPage>=$pageCount-1,false);

 // last page
 $buttons[]=$this->createPageButton($this->lastPageLabel,$pageCount-1,self::CSS_LAST_PAGE,$currentPage>=$pageCount-1,false);
 
 // 頁數(shù)統(tǒng)計
 $buttons[]=$this->createTotalButton(($currentPage+1)."/{$pageCount}",self::CSS_TOTAL_PAGE,false,false);
 
 // 條數(shù)統(tǒng)計
 $buttons[]=$this->createTotalButton("共{$this->getItemCount()}條",self::CSS_TOTAL_ROW,false,false);

 return $buttons;
 }
 
 protected function createTotalButton($label,$class,$hidden,$selected)
 {
 if($hidden || $selected)
  $class.=' '.($hidden ? self::CSS_HIDDEN_PAGE : self::CSS_SELECTED_PAGE);
 return '<li class="'.$class.'">'.CHtml::label($label,false).'</li>';
 }
 
 /**
 * 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('application.components.views.LinkPager.pager').'.css');
 Yii::app()->getClientScript()->registerCssFile($url);
 }
}

定義CSS樣式

/**
 * 翻頁樣式
 */
.page_blue{
 margin: 3px;
 padding: 3px;
 text-align: center;
 font: 12px verdana, arial, helvetica, sans-serif;
}
ul.bluePager,ul.yiiPager
{
 font-size:11px;
 border:0;
 margin:0;
 padding:0;
 line-height:100%;
 display:inline;
 text-aligin:center;
}

ul.bluePager li,ul.yiiPager li
{
 display:inline;
}

ul.bluePager a:link,ul.yiiPager a:link,
ul.bluePager a:visited,ul.yiiPager a:visited,
ul.bluePager .total_page label,ul.yiiPager .total_page label,
ul.bluePager .total_row label,ul.yiiPager .total_row label
{
 border: #ddd 1px solid;
 color: #888888 !important;
 padding:2px 5px;
 text-decoration:none;
}

ul.bluePager .page a,ul.yiiPager .page a
{
 font-weight:normal;
}

ul.bluePager a:hover,ul.yiiPager a:hover
{
 color:#FFF !important; border:#156a9a 1px solid; background-color:#2b78a3
}

ul.bluePager .selected a,ul.yiiPager bluePager .selected a
{
 color:#3aa1d0 !important;
 border: 1px solid #3aa1d0;
}

ul.bluePager .selected a:hover,ul.yiiPager .selected a:hover
{
 color:#FFF !important;
}

ul.bluePager .hidden a,ul.yiiPager .hidden a
{
 border:solid 1px #DEDEDE;
 color:#888888;
}

ul.bluePager .hidden,ul.yiiPager .hidden
{
 display:none;
}

controller中操作:

//分頁操作
$criteria=new CDbCriteria;
$criteria->order='id DESC';
$criteria->select=array('id','uid','username','title','thumb','url','clicks','time','dateline','countfavorite','quality');
$criteria->condition=$sql;
$total = Video::model()->count($criteria);

$pages = new CPagination($total);  
$pages->pageSize=self::PAGE_SIZE;
$pages->applyLimit($criteria);
  
$list = Video::model()->findAll($criteria);

$title = CommonClass::model()->find(array(
 'select'=>array('cname'),
 'condition'=>'id = '.$id,
));  

$this->render('application.views.video.list',array(
 'array'=>$array,
 'arr'=>$arr,
 'result'=>$result,
 'list'=>$list,
 'pages'=>$pages,
 'title'=>$title,
));

在views/video/list.php中引用:

<?php
 $this->widget('LinkPager', array('pages' => $pages,));
 ?>

相關(guān)文章

  • php之Smarty模板使用方法示例詳解

    php之Smarty模板使用方法示例詳解

    這篇文章主要介紹了php之Smarty模板的使用方法,需要的朋友可以參考下
    2014-07-07
  • php使用flock阻塞寫入文件和非阻塞寫入文件的實例講解

    php使用flock阻塞寫入文件和非阻塞寫入文件的實例講解

    下面小編就為大家?guī)硪黄猵hp使用flock阻塞寫入文件和非阻塞寫入文件的實例講解。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07
  • Laravel利用gulp如何構(gòu)建前端資源詳解

    Laravel利用gulp如何構(gòu)建前端資源詳解

    Gulp 是一個自動化工具,前端開發(fā)者可以使用它來處理常見任務(wù),下面這篇文章主要給大家介紹了關(guān)于Laravel利用gulp如何構(gòu)建前端資源的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧
    2018-06-06
  • 淺談Laravel核心解讀之Console內(nèi)核

    淺談Laravel核心解讀之Console內(nèi)核

    這篇文章主要介紹了淺談Laravel核心解讀之Console內(nèi)核,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-12-12
  • PHP檢測移動設(shè)備類mobile detection使用實例

    PHP檢測移動設(shè)備類mobile detection使用實例

    這篇文章主要介紹了PHP檢測移動設(shè)備類mobile detection使用實例,mobile detection可以檢測到絕大部分手機、平板電腦的操作系統(tǒng)、瀏覽器等數(shù)據(jù),需要的朋友可以參考下
    2014-04-04
  • PHP實現(xiàn)下載遠(yuǎn)程圖片保存到本地的方法

    PHP實現(xiàn)下載遠(yuǎn)程圖片保存到本地的方法

    本篇文章主要介紹了PHP實現(xiàn)下載遠(yuǎn)程圖片的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • PHP無限分類(樹形類)

    PHP無限分類(樹形類)

    PHP無限分類,Google一下就能找到很多相關(guān)資料,思路比較拉風(fēng)的,也是用得比較多的就是分類表至少有id,pid,name三個字段,id自增表分類,pid為父分類,name為分類名,這樣就構(gòu)成了一棵樹,如下,算是我查詢分類表得到的結(jié)果集
    2013-09-09
  • Symfony2創(chuàng)建頁面實例詳解

    Symfony2創(chuàng)建頁面實例詳解

    這篇文章主要介紹了Symfony2創(chuàng)建頁面的方法,結(jié)合實例形式分析了Symfony頁面創(chuàng)建的具體步驟與相關(guān)實現(xiàn)技巧,需要的朋友可以參考下
    2016-03-03
  • 解決yii2左側(cè)菜單子級無法高亮問題的方法

    解決yii2左側(cè)菜單子級無法高亮問題的方法

    這篇文章主要為大家詳細(xì)介紹了解決yii2左側(cè)菜單子級無法高亮問題的方法,感興趣的朋友可以參考一下
    2016-05-05
  • 基于php流程控制語句和循環(huán)控制語句(講解)

    基于php流程控制語句和循環(huán)控制語句(講解)

    下面小編就為大家?guī)硪黄趐hp流程控制語句和循環(huán)控制語句(講解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10

最新評論