Home  >  Article  >  php教程  >  How to implement paging in YII

How to implement paging in YII

高洛峰
高洛峰Original
2016-12-23 17:07:241118browse

This article briefly describes the method of paging in Yii with example code for reference by friends who are learning Yii. The specific code is as follows:

1. Controller part code:

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));
}

2. View part code:

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

For more articles related to how YII implements paging, please pay attention to the PHP Chinese website!

Statement:
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