Using yii2's gridview with a normal array of d

2020-07-03 07:44发布

I have an array of data very similar to this

[
    'name'=>'mark',
    'age'=> '21'
    'height'=> '190 cm'
]

I searched Google and all the results i found were using an active record object.

How do i use the gridview with an array of this sort?

标签: php yii2
1条回答
狗以群分
2楼-- · 2020-07-03 08:28

You should use ArrayDataProvider (https://github.com/yiisoft/yii2/blob/master/framework/data/ArrayDataProvider.php)

$provider = new ArrayDataProvider([
    'allModels' => $yourArray,
    'sort' => [
        'attributes' => ['id', 'username', 'email'],
    ],
    'pagination' => [
        'pageSize' => 10,
    ],
]);
查看更多
登录 后发表回答