search
Homephp教程php手册YII实现分页的方法,YII实现分页方法

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

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

yii分页问题,着急用

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

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

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

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use