yii CArrayDataProvider进行分页

YII cooljun 351℃ 0评论

利用CArrayDataProvider,可以对一个数组里面的数据进行分页
php代码如下
 public function
actionPage(){
           $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));
       }
在页面展示的时候使用CGridView进行数据显示
 $this->widget(‘zii.widgets.grid.CGridView’,
array(
         ‘id’=>’effectivepolicy-grid’,
         ‘dataProvider’=>$dataProvider,
         ’emptyText’=>’没有找到数据.’,
         ‘nullDisplay’=>’-‘,
         ‘columns’=>array(
            
            array(
               ‘name’=>’用户名’,
               ‘value’=>’$data[“username”]’,
               ‘htmlOptions’=>array(‘style’=>’width:55px;’)
            ),
                               array(
               ‘name’=>’密码’,
               ‘value’=>’$data[“password”]’,
               ‘htmlOptions’=>array(‘style’=>’width:55px;’)
            ),
         ),
       ));

转载请注明:cooljun小站 » yii CArrayDataProvider进行分页

如果你觉得这篇文章对你有帮助,请支持我继续更新网站 !捐赠本站
喜欢 (0)or分享 (0)
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址