how to use CArrayDataProvider
CArrayDataProvider need for cases when you want pass an array to CGridView.
Key id must be in an array or it will not work.
$fruits = array(
array('id' => 1, 'name'=>'apple', 'color' => 'green'),
array('id' => 2, 'name'=>'orange', 'color' => 'orange'),
array('id' => 3, 'name'=>'banana', 'color' => 'yellow'),
array('id' => 4, 'name'=>'pineapple', 'color' => 'brown')
);
$dataProvider = new CArrayDataProvider($fruits);
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'fruits-grid',
'dataProvider' => $dataProvider ,
'columns' => array(
array(
'name' => 'ID',
'value' => '$data["id"]',
),
array(
'name' => 'Name',
'value' => '$data["name"]'
),
array(
'name' => 'Color',
'value' => '$data["color"]'
),
)
));
Written by Аспирин Хаостиков
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#