Yii使用ZF的分页方式
来源:互联网 发布:8051单片机基本特点 编辑:程序博客网 时间:2024/04/28 16:25
使用类似ZF的方式分页,需要单独写一个分页类,重载run方法,从CPagination得到需要的分页数据,然后使用控制器的renderPartial方法,不能使用render方法这个方法会在视图的控制器目录下找文件,这样指定的位置就不准确了。
<?php/*** 解决使用rpc来的数据没有相应的数据提供者的问题* 这里不使用dataProvider,仅仅用分页器和模板来显示分页页面*/class SLinkPager extends CBasePager{ /** * 分页器使用的视图文件 * @var string */ public $itemView; /** * @var integer maximum number of page buttons that can be displayed. Defaults to 10. */ public $maxButtonCount=10; /** * Initializes the pager by setting some default property values. */ public function init() { if($this->itemView===null) throw new CException(Yii::t('linkpager','The property "itemView" cannot be empty.')); } /** * Executes the widget. * This overrides the parent implementation by displaying the generated page buttons. */ public function run() { $this->registerClientScript(); if(($pageCount=$this->getPageCount())<=1) return; $data = array(); $data['pageCount'] = $this->getPageCount(); list($data['beginPage'],$data['endPage'])=$this->getPageRange(); $data['pagesInRange'] = range($data['beginPage'], $data['endPage']); $data['current']=$this->getCurrentPage(false); if ($data['endPage'] > $data['current']) { $data['next'] = $data['current']+1; } if ($data['current'] > $data['beginPage']) { $data['prev'] = $data['current']-1; } $data['pager']=$this->getPages(); $owner=$this->getOwner(); $owner->renderPartial($this->itemView,$data, false); }
类中重点是run这块,另外添加itemView属性,再看模板里面
<!--See h ttp://developer.yahoo.com/ypatterns/pattern.php?pattern=searchpagination--><?php if ($pageCount): ?>< div class ="page" ><?php if ( isset($prev )): ?>< a href =" <?php echo $pager->createPageUrl($this, $prev); ?>" > 上一页< b ></b ></ a><?php endif ;?><?php foreach ($pagesInRange as $page): ?><?php if ($page != $current ): ?> <a href= "<?php echo $pager->createPageUrl($this, $page); ?> "> <?php echo $page+1; ?> </ a><?php else : ?> <a href= "#" class ="focus" > <?php echo $page+1; ?> </ a> <?php endif ; ?><?php endforeach ; ?><?php if ( isset($next )): ?>< a href =" <?php echo $pager->createPageUrl($this, $next); ?>" > 下一页< b ></b ></ a><?php endif ;?></ div><?php endif ;?>
这些写就OK了,最后是widget渲染部分,
<?php $this->widget( 'SLinkPager', array ('pages' => $pager, 'itemView' => 'widget/pagination')); ?>
这里的$pager是CPagination,个人认为ZF的这种方式可以不管分页结构和样式,直接把模板拿来套用就行。
提醒,这个renderPartial方法我重载了的,自己写的时候看看文档的实现,可能和我的不一样。
一句抱怨,为什么yii的分页的页码是从0开始的呢,这个到处都有修改,如果忘记了页面就错了,不是没事找事吗。
资料:
http://www.yiiframework.com/
http://www.yiichina.com/forum/thread-143-1-1.html
- Yii使用ZF的分页方式
- yii分页组件的使用
- yii分页组件的使用
- ZF 资料库的使用
- YII分页类可以使用的参数
- yii中分页功能的使用
- yii框架ajax分页的使用
- Yii中分页类的使用
- Yii Framework使用DAO方式查询分页代码
- Yii使用CPagination分页
- yii视图使用的widget方式总结
- Yii框架的分页
- ZF和yii性能对比
- 在yii中使用分页
- yii框架-yii2分页的使用与扩展(十五)
- Yii 分页CLinkPager使用Bootstrap样式分页
- Yii中的layouts使用(header,footer的使用方式)
- yii框架分页的实现
- Use Dojo in the ZF
- css中中文字体(font-family)的英文名称
- c++ 函数名后面的const
- “程序员”真的是“IT民工”?
- SiteMesh:一个优于Apache Tiles的Web页面布局、装饰框架
- Yii使用ZF的分页方式
- Python标准库01 正则表达式 (re包)
- Smarty学习笔记二:cache与plugin
- 深入研究Hibernate之五:三种状态
- WINCE7.0 获取CPU,MEMORY等硬件和系统信息
- 使用IDA 分析高级数据结构
- linux下运用scp来进行传输无需要密码
- 《深入理解Linux内核》copy_process之dup_task_create函数
- 求最大成绩学生的学位号