yii自己定义CLinkPager分页
在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分页的更多相关文章
- Yii 自带的分页实例
yii自带的分页很好用,简单的几行代码就能把分页搞出来,唯一恼火的是只能写在controller中,所以有时候controller中的方法有点臃肿.废话少说,上代码上图. 一.代码实例: 1.控制器中 ...
- Yii Framework2.0开发教程(4)在yii中定义全局变量
在yii中定义全局变量最好的地方是入口脚本处.也就是web目录中的index.php文件 比如我们在defined('YII_ENV') or define('YII_ENV', 'dev');后写上 ...
- Yii 框架ajax搜索分页
要想实现ajax搜索分页 其实很简单 第一步:在 Yii 框架自带的搜索和分页正常运行的情况下,在视图层
- yii使用bootstrap分页样式
Bootstrap是Twitter推出的一个开源的用于前端开发的工具包.它由Twitter的设计师Mark Otto和Jacob Thornton合作开发,是一个CSS/HTML框架.Bootstra ...
- NET Core-TagHelper实现分页标签
这里将要和大家分享的是学习总结使用TagHelper实现分页标签,之前分享过一篇使用HtmlHelper扩展了一个分页写法地址可以点击这里http://www.cnblogs.com/wangrudo ...
- Yii源码阅读笔记(三十四)
Instance类, 表示依赖注入容器或服务定位器中对某一个对象的引用 namespace yii\di; use Yii; use yii\base\InvalidConfigException; ...
- 使用Yii框架完整搭建网站流程入门
下载地址: http://www.yiiframework.com/ http://www.yiichina.com/ 由美籍华人薛强研究而出, Yii 这个名字(读作易(Yee))代表 简单(eas ...
- MVC下分页的自定义分页一种实现
1.引言 在MVC开发中我们经常会对数据进行分页的展示.通过分页我们可以从服务端获取指定的数据来进行展示.这样既节约了数据库查询的时间也节约了网络传输的数据量.在MVC开发中使用的比较多的应该是MVC ...
- 【Bootstrap】Bootstrap和Java分页-第一篇
目录 关于此文 pagination BetweenIndex DefaultPagination QueryHandler BookDaoImpl BookServiceImpl BookActio ...
随机推荐
- 英语发音规则---C字母
英语发音规则---C字母 一.总结 一句话总结: 1.C发[k]音? cake [keɪk] n. 蛋糕 coat [kəʊt] n. 外套 music ['mjuːzɪk] n. 音乐,乐曲 pic ...
- Java-MyBatis:MyBatis 中 in 的用法
ylbtech-Java-MyBatis-杂项:MyBatis 中 in 的用法 1.返回顶部 1. foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合.foreach元 ...
- ROS-SLAM仿真-cartographer
前言:cartographer是谷歌2016年发布的一个开源slam算法,采用基于图网络的优化方法,主要基于激光雷达来实现. 使用源码编译方式. 一.新建工作空间 1.1 使用roboware新建名为 ...
- Request.QueryString["id"] 、Request.Params["id"] 的强大
<form> <input type="text" name="id" value="值"> </form&g ...
- Java基础——GridBagLayout布局
1.GridBagLayout布局管理器非常灵活,每个 GridBagLayout 对象维持一个动态的矩形单元网格: 2.需要和它的约束类(GridBagConstraints类)一起使用: 3.Gr ...
- C++_String_类字符串操作(转)
从百度文库找的,挺详细的,跟大家分享一下. 标红的是我觉得用的比较多,并且大家不太熟悉的. string类的构造函数: string(const char *s); //用c字符串s初始化 s ...
- day09-1 列表,元祖的内置方法
目录 列表类型的内置方法 作用 定义方式 方法 优先掌握 需要掌握 储存一个值or多个值 有序or无序?(有序:有索引, 无序:无索引) 可变or不可变(可变:值变id不变,不可变:值变id也变) 元 ...
- Pyhton学习——Day38
#CSS:Cascading Style Sheets——层叠样式表# CSS的四种引入方式# 行内式是在标记的style属性中设定CSS样式.这种方式没有体现出CSS的优势,不推荐使用.###### ...
- 亲历:IT 从业者避免猝死攻略 v1.0
作者:香蕉痞 出处:http://www.geekpark.net/read/view/191188?u=0 亲历:IT 从业者避免猝死攻略 v1.0 By 香蕉痞 | 2013/10/28 [核心提 ...
- Java 应用运维
作者:http://blogread.cn/it/article/4918?f=wb 出处:http://blogread.cn/it/article/4918?f=wb Java应用运维 出处 ...