首页 > 代码库 > YII框架CGridView分页实现

YII框架CGridView分页实现

C控制器层

$model = new User(‘search‘);        $model->unsetAttributes();        $dataProvider = $model->search();$this->render(‘company‘,array(            ‘dataProvider‘=>$dataProvider,            ‘model‘=>$model,        ));

 解释:$model->unsetAttributes();将属性置空;

V视图层

$this->widget(‘zii.widgets.grid.CGridView‘, array(        ‘itemsCssClass‘ => ‘table table-striped table-bordered table-hover‘,        ‘pagerCssClass‘=>‘margin-top-20‘,        ‘htmlOptions‘=>array(‘class‘=>‘portlet-body‘),        ‘pager‘=>array(            ‘class‘=>‘CLinkPager‘,            ‘header‘=>‘‘,            ‘htmlOptions‘=>array(‘class‘=>‘pagination‘),        ),        ‘dataProvider‘=>$dataProvider,        ‘columns‘=>array(
       /*array(
          //添加复选框
                ‘htmlOptions‘=>array(‘width‘=>"30px"),
                ‘class‘ => ‘CCheckBoxColumn‘,
                ‘name‘=>‘checkbox[]‘,
                ‘value‘=>‘$data->id‘,
                ‘id‘=>‘checkbox‘,
                ‘headerTemplate‘=>‘{item}‘,
                ‘selectableRows‘=>2,
            ),*/ ‘id‘, array( ‘name‘=>‘status‘, ‘value‘=>‘$data->status == 0 ? "待审" : (($data->status == 1) ? "正常" : "屏蔽")‘ ), ‘email‘, ‘company_name‘, ‘company_full_name‘, ‘company_detail_addr‘, ‘login_ip‘, ‘last_login_time‘,
       /*array(
                //增删改查按钮
                ‘class‘=>‘CButtonColumn‘,
            ),*/ ), )); ?>

 解释:columns放置表的列名,itemsCssClass表的class属性,pager为分页

YII框架CGridView分页实现