Home > php教程 > php手册 > body text

YII实现分页的方法,YII实现分页方法

WBOY
Release: 2016-06-13 09:29:13
Original
1019 people have browsed it

YII实现分页的方法,YII实现分页方法

本文以实例代码简述了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

yii分页问题,着急用

sql用limit和offset。分页用$pages = new CPagination ();
 

教怎在YII中实现三个公共方法

你可以先看下基础的教程,尝试使用AR模型,这样子的话,你可以先建一个posts表,存储发布信息的公共部分,这样所有资源可以在一个基础模型里,利用gii可以生成模型和CURD所有代码,然后再根据posts里设置一个资源类型,利用id关联到不同的资源表,至于标签,可另设一个表,关联过去即可。
 

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