- php;toolbar:false">/*public function actionReport()
- {
- $sql = "select * from {{goods}}";
- $criteria=new CDbCriteria();
- $result = Yii::app()->db->createCommand($sql)->query();
- $pages=new CPagination($result->rowCount);
- $pages->pageSize=2;
- $pages->applyLimit($criteria);
- $result=Yii::app()->db->createCommand($sql." LIMIT :offset,:limit");
- $result->bindValue(':offset', $pages->currentPage*$pages->pageSize);
- $result->bindValue(':limit', $pages->pageSize);
- $goodsInfo=$result->query();
- $this->render('index',array(
- 'goodsInfo'=>$goodsInfo,
- 'pages'=>$pages,
- ));
- }*/
商品name | 价格 | 更新时间 | - foreach($goodsInfo as $v){
- ?>
| | | - }
- ?>
- //分页widget代码:
- $this->widget('CLinkPager',array('pages'=>$pages));
- ?>
方式二,使用自己的分页类来完成分页
1,控制器代码:
public function actionIndex(){ - $goods_m=goods::model();
//1.获得商品总的记录数目 - $cnt = $goods_m -> count();
//2. 实例化分页类对象 - $page = new Page($cnt, 2);
//3. 重新按照分页的样式拼装sql语句进行查询 - $sql = "select * from {{goods}} $page->limit";
- $goodsInfo = $goods_m -> findAllBySql($sql);
//4. 获得分页页面列表(需要传递到视图模板里边显示) - $pageList = $page->fpage();
$this->renderPartial('index',array('goodsInfo'=>$goodsInfo,'pageList'=>$pageList)); - }
2,视图代码:
商品name | price | create_time | - foreach($goodsInfo as $v){
- ?>
| | | - }
- ?>
- echo $pageList;
- ?>
-
分页类要放到能自动加载到的目录下就行; |