我有一系列与此非常相似的数据
$array = [
'FUNDSCTR' => '10000001'
'RCMMTITEM' => 'R400001'
'YEAR' => '2018'
'CONSUMA' => 5898257
'CONSUME' => 30140
'AVAIL' => 5868117 ]
并在ArrayDataProvider中使用
$dataProvider = new ArrayDataProvider(['allModels' => $array,]);
gridview中的代码
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'kartik\grid\SerialColumn'],
[
'label' => 'Year',
'attribute'=>'YEAR',
],
[
'label' => 'Fund',
'attribute'=>'FUNDSCTR',
],
[
'label' => 'Item',
'attribute'=>'RCMMTITEM',
],
[
'label' => 'Consumeable',
'attribute'=>'CONSUMA',
],
[
'label' => 'Consumed',
'attribute'=>'CONSUME',
],
[
'attribute'=>'Available',
'value'=> 'AVAIL',
],
]);
?>
</div>
print_r($ dataProvider); 〜$ arrays返回
yii\data\ArrayDataProvider Object ( [key] => [allModels] => Array ( [RFUNDSCTR] => 10000001 [RCMMTITEM] => R400013 [RYEAR] => 2018 [CONSUMA] => 5898257 [CONSUME] => 30140 [AVAIL] => 5868117 )
我需要在gridView中显示这样的数据。
答案 0 :(得分:2)
要正常工作,传递给ArrayDataProvider的数组应该是二维的,如下所示:
$array = [
[
'FUNDSCTR' => '10000001',
'RCMMTITEM' => 'R400001',
'YEAR' => '2018',
'CONSUMA' => 5898257,
'CONSUME' => 30140,
'AVAIL' => 5868117,
],
[
'FUNDSCTR' => '10000001',
'RCMMTITEM' => 'R400001',
'YEAR' => '2018',
'CONSUMA' => 5898257,
'CONSUME' => 30140,
'AVAIL' => 5868117,
],
[
'FUNDSCTR' => '10000001',
'RCMMTITEM' => 'R400001',
'YEAR' => '2018',
'CONSUMA' => 5898257,
'CONSUME' => 30140,
'AVAIL' => 5868117,
]
];