本文实例讲述了Yii视图操作之自定义分页实现方法。分享给大家供大家参考,具体如下:
1. 视图文件调用cgridview,clistview时候调用自定义的分页方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
<?php $this ->widget( 'zii.widgets.grid.CGridView' , array ( 'id' => 'news-grid' , 'dataProvider' => $model ->search(), 'filter' => $model , 'template' => '{items}{summary}{pager}' , 'selectableRows' =>2, 'pager' => 'ZPager' , 'summaryText' => '页数:{pages}/{page}页' , 'columns' => array ( array ( 'class' => 'CCheckBoxColumn' , 'footer' =>'<button onclink= "deleteAll()" >button</button> <button onclink= "refashAll()" >button</button>', 'footerHtmlOptions' => array ( 'colspan' =>5), 'selectableRows' =>2, ), 'id' , array ( 'name' => 'title' , 'htmlOptions' => array ( 'width' => '20%' ), 'value' => 'mb_substr($data->title,0,10,"utf-8")' , ), array ( 'name' => 'content' , 'htmlOptions' => array ( 'width' => '20%' ), 'value' => 'mb_substr(strip_tags($data->content),0,10,"utf-8")' , ), array ( 'name' => 'type' , 'value' => 'News::model()->getNewsType($data->type)' , ), 'user' , array ( 'name' => 'status' , 'value' => 'News::model()->getNewsStatus($data->status)' , ), array ( 'class' => 'CButtonColumn' , 'buttons' => array ( 'view' => array ( 'visible' => 'false' ), //'delete'=>array('click'=>'true'), ), ), ), )); |
2. 复制基类分页类文件,做修改成为自己的分页方法
framework/web/widgets/pagers/CListPager.php复制并生命名到protected/components/zpager.php修改类名称
framework/web/widgets/pagers/pager.css复制对应样式文件到protected/components/css/pager.css
修改zpager.php的css加载目录
1
2
3
4
5
6
|
public static function registerCssFile( $url =null) { if ( $url ===null) $url =CHtml::asset(Yii::getPathOfAlias( 'application.components.css.pager' ). '.css' ); Yii::app()->getClientScript()->registerCssFile( $url ); } |
3. 通过修改Css样式文件,也可以修改生成列表的程序,达到修改分类的目的。
希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。