支付宝赞助帐号:service@kuitao8.com 

yii2.0 利用Activedataprovider分页

Created2015-07-06   Views 5993    Author 懒人程序
yii2.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]);
}

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']],
]);
上一篇: php禁用ip访问的简单实现方法
下一篇: Yii2 rules常用规则说明
支持键盘 ← →

邮件订阅

订阅我们的精彩内容