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

YII实现分页的方法_PHP

WBOY
Release: 2016-06-01 11:51:59
Original
857 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