小伙儿 2014-08-21 10:36:35 23827次浏览 11条评论 33 1 0

下面小伙介绍一下 Activedataprovider 类分页的使用

use yii\data\ActiveDataProvider;  这是必须的步骤,因为我们要使用 ActiveDataProvider 类
use common\models\User;

public function actionList()
{
     $model = new User();
     $dataProvider = new ActiveDataProvider([
        'query' => $model->find(),
        'pagination => [
                'pagesize' => '10',
         ]
       ]);

      return $this->render('list', ['model' => $model, 'dataProvider' => $dataProvider]);
}

view代码
list.php

use yii\grid\GridView;  这是必须的;


GridView::widget([
         'dataProvider' => $dataProvider,
         'columns' => [
         'attribute',(attribute为字段的名称,开发时候根据自己的需要进行修改)
         [
               'attribute' => 'create_time',
               'format' => ['data', 'Y-m-d H:i:s'],
               'options' => ['width' => '200']
         ]],
         ['class' => 'yii\grid\ActionColumn', 'header' => '操作', 'headerOptions' => ['width' => '80']],
]);

原文链接:http://blog.sina.com.cn/s/blog_88a65c1b0101j0md.html

觉得很赞
您需要登录后才可以评论。登录 | 立即注册