Home > Backend Development > PHP Tutorial > YII实现分页的方法_php实例

YII实现分页的方法_php实例

WBOY
Release: 2016-05-17 08:39:24
Original
1059 people have browsed it

本文以实例代码简述了yii实现分页的方法,供学习yii的朋友参考,具体代码如下:

1.控制器部分代码:    

public function actionTest() 
{ 
$criteria=new CDbCriteria; 
$criteria->order='id DESC'; 
$count=User::model()->count($criteria); 
$pager=new CPagination($count); 
$pager->pageSize=10; 
$pager->applyLimit($criteria); 
$userList=User::model()->findAll($criteria); 
$this->render('test',array('list'=>$userList,'pages'=>$pager)); 
} 
Copy after login

2.视图部分代码:

<&#63;php 
foreach($list as $o) 
{ 
echo $o->username.'<br/>'; 
echo $o->id.'<br/>'; 
} 
$this->widget('CLinkPager',array( 
'header'=>'', 
'firstPageLabel' => '首页', 
'lastPageLabel' => '末页', 
'prevPageLabel' => '上一页', 
'nextPageLabel' => '下一页', 
'pages' => $pages, 
'maxButtonCount'=>13 
) 
); 
&#63;>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template