需求及效果图如下

没什么说的,就是修改分页,修改了CLinks分页的样式

上代码

<?php

class GsearchPager extends CBasePager
{
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);
}
}

  放哪都行,只要在配置文件中 import 进来就好

protected/config/config.php

return array(
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'application.helpers.*',
'application.utils.*',
),
//...
)

  使用方法和clink是一样的

<div class="paging">
<?php $this->widget('application.widgets.GsearchPager', array(
'header'=>'',
//'firstPageLabel'=>'首页',
//'lastPageLabel'=>'末页',
'prevPageLabel'=>'<上一頁',
'nextPageLabel'=>'下一頁>',
'pages' => $viewData['pages'],
'maxButtonCount'=>6,
)) ?>
</div>

  

yii 分页样式的更多相关文章

  1. yii使用bootstrap分页样式

    Bootstrap是Twitter推出的一个开源的用于前端开发的工具包.它由Twitter的设计师Mark Otto和Jacob Thornton合作开发,是一个CSS/HTML框架.Bootstra ...

  2. DataPager 分页样式(css)

    <asp:DataPager ID="> <Fields> <asp:NextPreviousPagerField ShowFirstPageButton=&q ...

  3. php分页类代码带分页样式效果(转)

    php分页类代码,有漂亮的分页样式风格 时间:2016-03-16 09:16:03来源:网络 导读:不错的php分页类代码,将类文件与分页样式嵌入,实现php查询结果的精美分页,对研究php分页原理 ...

  4. 打造简单实用的Thinkphp分页样式(Bootstrap版本)

    先吐槽一下ThinkPHP3.1版的分页样式,虽然看起来也很简单大方,但是所有的页码全是使用简单的数字,之间的空隙比较小,不大容易点,还有那个“前5页”和“后5页”显得有点多余,因为点击当前显示第一页 ...

  5. bootstrap 分页样式代码

    bootstrap 分页样式代码,废话不多说,直接上源码 <!DOCTYPE html> <html> <head> <title>Bootstrap ...

  6. 帝国cms 列表页分页样式修改美化【2】

    上一篇(帝国cms 列表页分页样式修改美化[1])中我们已经对分页说了一个大概,下面我们就自己动手弄一个分页把: 第一步:进入帝国cms后台,点击系统设置->系统参数设置->信息设置:里面 ...

  7. 帝国cms 列表页分页样式修改美化【1】

    [1]自己修改帝国cms默认的分页样式(css),这样做的好处是你不用去改动帝国的核心文件,方便以后升级. [2]自己动手去修改帝国的分页(php+css),帝国的分页在e>class>下 ...

  8. 修改DeDe标签Pagelist分页样式

    我们在用dede仿站的时候,调用文章列表页的分页时,我们会用到: {dede:pagelist listitem=”info,index,end,pre,next,pageno” listsize=” ...

  9. 帝国cms分页样式修改文件-注意事项

    帝国cms分页样式主要有:内容页分页样式.列表页分页样式以及默认搜索模板使用的搜索样式等几种. 要改这些样式其实也很简单,在网站目录中找到相应的.css文件修改empages属性就行了,但是这样比较麻 ...

随机推荐

  1. 访问快递100的rest的请求

    转:http://blog.csdn.net/u011115507/article/details/9172679 查快递的时候发现了一个http://www.kaidi100.com 是金蝶旗下的下 ...

  2. 重拾C++ 基础知识总结(二)

    1.标准库string类型: 用户程序要使用string类型对象,必须包含相关头文件 #include <string> 字符串字面值与标准库string类型不是同一种类型,字符串字面值是 ...

  3. linux的du和df命令

    今天也有同学问我Linux下查看目录大小的命令,现在也将前阵子学习到du/df两个命令总结一下吧.前阵子测试工作中有遇到过由于磁盘空间满导致程序无法执行到情况,所以使用了df和du两个命令. du查看 ...

  4. 如何把powerpoint幻灯片大小改为标准或宽屏教程【图文】

    不知道大家还记得早期powerpoint版本,幻灯片的形状是较方(4:3),随着科技的发展,很多电视.视频都在用宽屏,powerpoint自然也是如此,现在默认的幻灯片大小是宽屏 (16:9),怎么把 ...

  5. Codeforces Round #313 A Currency System in Geraldion

    A  Currency System in Geraldion Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64 ...

  6. JS 输出与变量

    1. JS的输出 innerHTML: <!DOCTYPE html> <html> <head> <meta charset="utf-8&quo ...

  7. 深度学习“引擎”之争:GPU加速还是专属神经网络芯片?

    深度学习“引擎”之争:GPU加速还是专属神经网络芯片? 深度学习(Deep Learning)在这两年风靡全球,大数据和高性能计算平台的推动作用功不可没,可谓深度学习的“燃料”和“引擎”,GPU则是引 ...

  8. Windows系统编程之进程间通信

    Windows系统编程之进程间通信作者:北极星2003来源:看雪论坛(www.pediy.com)Windows 的IPC(进程间通信)机制主要是异步管道和命名管道.(至于其他的IPC方式,例如内存映 ...

  9. BZOJ1627: [Usaco2007 Dec]穿越泥地

    1627: [Usaco2007 Dec]穿越泥地 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 478  Solved: 303[Submit][Sta ...

  10. 【博弈论】HDU 5754 Life Winner Bo

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5754 题目大意: 4种棋子,象棋中的 1王,2车,3马,4后,选其一,B和G轮流走,不能往左上走,一 ...