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 ...
随机推荐
- Server Tomcat v8.0 Server at localhost was unable to start within 45 seconds. If the server requires
Server Tomcat v8.0 Server at localhost was unable to start within 45 seconds. If the server requires ...
- 数组进行多少次OP操作,才干有序
1 题目描写叙述: 有一个数组:2,1,4,3.对于数组,有一种操作op(idx):将该index相应的数字移到首位.比方: op(3): 2 1 43 -> 3 2 1 4 op(1): ...
- c++面向对象程序设计 谭浩强 第五章答案
1: #include <iostream> using namespace std; class Student {public: void get_value() {cin>&g ...
- Hessian实例
简述Hessian Hessian是一个由Caucho Technology开发的轻量级RPC框架,由于它使用二进制RPC协议,所以它更快.更简单,很适合于发送二进制数据(访问官网): 在进行基于He ...
- ROS-多机通信
前言:一定要在同一路由的局域网下进行,就是两台电脑的ip要像这样:192.168.191.4和192.168.191.8,只有最后一位不同,这样就能ping通了,否则ping不同. 一.查看ip和主机 ...
- JVM源码分析之javaagent原理完全解读--转
原文地址:http://www.infoq.com/cn/articles/javaagent-illustrated 概述 本文重点讲述javaagent的具体实现,因为它面向的是我们Java程序员 ...
- LeetCode224. Basic Calculator (用栈计算表达式)
解题思路 用两个栈分别存字符和数字. 顺序读入字符,处理方式分为字符和数字两种. 处理字符分为')'和非')'两种. 处理数字需要读取字符栈栈顶,分为'+'.'-'和非'+'.'-'. 代码 clas ...
- Android 让系统自动生成缩略图并写入媒体库
MediaStore.Video.Thumbnails.getThumbnail(ContentResolver cr, long origId, int kind, BitmapFactory.Op ...
- 在HTTP页面输入数据,Chrome 70将显示红色不安全警告
2018年10月17日,Chrome 70版本正式发布,该版本更新多项安全功能,再次升级对HTTP页面的不安全警告样式.当用户在HTTP页面输入数据时,Chrome 70将显示醒目的红色不安全警告,让 ...
- 改变浏览器页面默认滚动条样式scrollbar
scrollbar-3d-light-color 设置或检索滚动条亮边框颜色scrollbar-highlight-color 设置或检索滚动条3D界面的亮边(ThreedHighlight)颜色sc ...