yii 分页 [ 1.1 版本 ]
$count = ChangeIntegral::model()->count($criteria);
$pages = new CPagination($count);
$pages->pageSize = Yii::app()->params['perPage'];
$pages->applyLimit($criteria);
$model = ChangeIntegral::model()->findAll($criteria);
$this->render('list', array('model' => $model, 'pages' => $pages));
上面的分页我会的
可是如果现在是这样的改怎么分页:
$data[] = array('id' => $v['id'], 'num' => $v['num'], 'name' => $model->coupon_name);
$this->render('suiteYhqList', array('data' => $data));
也就是数据是自己定义的$data[]
不是一个模型对象$model
共 1 个回答
-
可以使用CArrayDataProvider
$rawData = array( array('id'=>1,'username'=>'aa','password'=>'aaaaaa'), array('id'=>2,'username'=>'bb','password'=>'aaaaaa'), array('id'=>3,'username'=>'cc','password'=>'aaaaaa'), array('id'=>4,'username'=>'dd','password'=>'aaaaaa'), array('id'=>5,'username'=>'ee','password'=>'aaaaaa'), array('id'=>6,'username'=>'ff','password'=>'aaaaaa'), array('id'=>7,'username'=>'gg','password'=>'aaaaaa'), array('id'=>8,'username'=>'hh','password'=>'aaaaaa'), array('id'=>9,'username'=>'jj','password'=>'aaaaaa'), array('id'=>10,'username'=>'qq','password'=>'aaaaaa'), array('id'=>11,'username'=>'www','password'=>'aaaaaa'), array('id'=>12,'username'=>'xx','password'=>'aaaaaa'), array('id'=>13,'username'=>'zz','password'=>'aaaaaa'), ); $dataProvider=new CArrayDataProvider($rawData, array( 'id'=>'user', 'sort'=>array( 'attributes'=>array( 'id', 'username', 'password', ), ), 'pagination'=>array( 'pageSize'=>10, ), )); $this->render('page',array('dataProvider'=>$dataProvider));
xyf90314
注册时间:2015-03-04
最后登录:2023-03-13
在线时长:95小时23分
最后登录:2023-03-13
在线时长:95小时23分
- 粉丝21
- 金钱5257
- 威望40
- 积分6607