我想在yii2中使用gridview中的arrayDataProvider。我跟着这个问题:
Using yii2's gridview with a normal array of data
现在我的数组显示在gridview中,但网格中delete / edit / view链接中的id参数是数组中无效id的数据索引。
如何将真实身份传递给这些行动?
编辑:
我的示例数组是这样的:
$data = [
23 => [
'id' => 4,
'title'=>'mark',
'parentName'=> '21',
'description'=> '190 cm'],
18 => [
'id'=>6,
'title'=>'aaa',
'parentName'=> 50,
'description'=> '190 cm'],
40 => [
'id'=> 8,
'title'=>'nnn',
'parentName'=> '34',
'description'=> '190 cm'],
];
答案 0 :(得分:1)
我猜你可以使用key
属性!
/**
* @var string|callable the column that is used as the key of the data models.
* This can be either a column name, or a callable that returns the key value of a given data model.
* If this is not set, the index of the [[models]] array will be used.
* @see getKeys()
*/
public $key;
https://github.com/yiisoft/yii2/blob/master/framework/data/ArrayDataProvider.php
答案 1 :(得分:1)
使用key
属性,这是一个示例
$provider = new ArrayDataProvider([
'allModels' => $data,
'key' => 'Review_ID',
'pagination' => [
'pageSize' => 10,
],
]);