Home > php教程 > PHP开发 > How to implement paging in YII

How to implement paging in YII

高洛峰
Release: 2016-12-23 17:07:24
Original
1134 people have browsed it

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));
}
Copy after login

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 
) 
); 
?>
Copy after login

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

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template