在components中自己定义LinkPager。并继承CLinkPager

代码例如以下:

<?

php
/**
* CLinkPager class file.
*
* @author liang.pingzheng
* @QQ 327168521
*/
class PLinkPager 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;
public $uri;
public $pageNum; //页数
/**
* Creates the page buttons.
* @return array a list of page buttons (in HTML code).
*/
private function getUri($pa){
$url=$_SERVER["REQUEST_URI"].(strpos($_SERVER["REQUEST_URI"], '? ')?'':"?").$pa;
$parse=parse_url($url); if(isset($parse["query"])){
parse_str($parse['query'],$params);
unset($params["page"]);
$url=$parse['path'].'? '.http_build_query($params);
}
return $url;
} protected function createPageButtons()
{
$this->uri=$this->getUri($pa='');
$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()
$this->pageNum = $pageCount; $buttons=array();
// 页数统计
$buttons[]=$this->createTotalButton(($currentPage+1)."/{$pageCount}",self::CSS_TOTAL_PAGE,false,false); // 条数统计
$buttons[]=$this->createTotalButton("共{$this->getItemCount()}条",self::CSS_TOTAL_ROW,false,false); // 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); $buttons[] = '  <input type="text" onkeydown="javascript:if(event.keyCode==13){var page=(this.value>'.$this->pageNum.')?'.$this->pageNum.':this.value;location=\''.$this->uri.'&page=\'+page+\'\'}" value="'.($currentPage+1).'" style="width:25px"><input type="button" value="GO" onclick="javascript:var page=(this.previousSibling.value>'.$this->pageNum.')?'.$this->pageNum.':this.previousSibling.value;location=\''.$this->uri.'&page=\'+page+\'\'">  '; 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;
}

view调用实例

    <?php
$this->widget('PLinkPager',array(
'prevPageLabel'=>'上一页',
'nextPageLabel'=>'下一页',
'pages' =>$pager,
'maxButtonCount'=>10,//分页数目
));
? >

yii自己定义CLinkPager分页的更多相关文章

  1. Yii 自带的分页实例

    yii自带的分页很好用,简单的几行代码就能把分页搞出来,唯一恼火的是只能写在controller中,所以有时候controller中的方法有点臃肿.废话少说,上代码上图. 一.代码实例: 1.控制器中 ...

  2. Yii Framework2.0开发教程(4)在yii中定义全局变量

    在yii中定义全局变量最好的地方是入口脚本处.也就是web目录中的index.php文件 比如我们在defined('YII_ENV') or define('YII_ENV', 'dev');后写上 ...

  3. Yii 框架ajax搜索分页

    要想实现ajax搜索分页 其实很简单 第一步:在 Yii 框架自带的搜索和分页正常运行的情况下,在视图层

  4. yii使用bootstrap分页样式

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

  5. NET Core-TagHelper实现分页标签

    这里将要和大家分享的是学习总结使用TagHelper实现分页标签,之前分享过一篇使用HtmlHelper扩展了一个分页写法地址可以点击这里http://www.cnblogs.com/wangrudo ...

  6. Yii源码阅读笔记(三十四)

    Instance类, 表示依赖注入容器或服务定位器中对某一个对象的引用 namespace yii\di; use Yii; use yii\base\InvalidConfigException; ...

  7. 使用Yii框架完整搭建网站流程入门

    下载地址: http://www.yiiframework.com/ http://www.yiichina.com/ 由美籍华人薛强研究而出, Yii 这个名字(读作易(Yee))代表 简单(eas ...

  8. MVC下分页的自定义分页一种实现

    1.引言 在MVC开发中我们经常会对数据进行分页的展示.通过分页我们可以从服务端获取指定的数据来进行展示.这样既节约了数据库查询的时间也节约了网络传输的数据量.在MVC开发中使用的比较多的应该是MVC ...

  9. 【Bootstrap】Bootstrap和Java分页-第一篇

    目录 关于此文 pagination BetweenIndex DefaultPagination QueryHandler BookDaoImpl BookServiceImpl BookActio ...

随机推荐

  1. Suffix Array 后缀数组

    后缀数组 顾名思义.SuffixArray(下面有时简称SA) 和字符串的后缀有关. 后缀:字符串中某个位置一直到结尾的子串.(SA中讨论包含了原串和空串).所以共同拥有len+1个后缀. 后缀数组: ...

  2. TNS-12555 / TNS-12560 / TNS-00525 Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPR

    TNS-12555 / TNS-12560 / TNS-00525 Error listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPR ...

  3. QFileSystemModel只显示名称,不显示size,type,modified

    Qt 提供的 QFileSystemModel可以提供文件目录树预览功能,但是预览的都自带了Name,size,type, modified等信息.我现在只想显示name这一列,不想显示size,ty ...

  4. redis.conf 配置项说明

    redis.conf 配置项说明如下: Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程   daemonize no 当Redis以守护进程方式运行时,Redis ...

  5. 使用CNN做电影评论的负面检测——本质上感觉和ngram或者LSTM同,因为CNN里图像检测卷积一般是3x3,而文本分类的话是直接是一维的3、4、5

    代码如下: from __future__ import division, print_function, absolute_import import tensorflow as tf impor ...

  6. 10. Regular Expression Matching[H]正则表达式匹配

    题目 Given an input string(s) and a pattern(p), implement regular expression matching with support for ...

  7. tomcat指定JDK版本

    在windows环境下以批处理文件方式启动tomcat,只要运行<CATALINA_HOME>/bin/startup.bat这个文件,就可以启动Tomcat. 在启动时,startup. ...

  8. java与javascript对cookie操作的工具类

    Java对cookie的操作 package cn.utils; import java.util.HashMap; import java.util.Map; import javax.servle ...

  9. javascript中封装获取样式属性值的兼容方法

    function getStyle(obj, attr) { if (window.getComputedStyle) { return window.getComputedStyle(obj, nu ...

  10. datatable.rows.indexof(dr)返回的是啥?

    返回的是Int类型的 行索引值,从0开始.也就是说,第一行是0.最后一行就是rows.count - 1.不会返回-1."这是第" + OldDt.Rows.IndexOf(ite ...