Hello.
I’ve made CGridView inside CAvtiveForm. CGridView uses my $dataProvider which is array of CActiveRecord (many rows od the same model). It works fine, I can edit data in rows, but problem is that, when I submit - my form in $_POST data send only last row. I am not supprised that it works like that since every input in my grid has the same name from the same model and they overwrites themselves in POST table and only last one is send.
I’ve tried to solve it but I can’t get good idea how to change names of my imputs (for eample add row number into name) or to make my form to treat that as Array of models.
Below sample of my code from view:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'form-id',
'enableAjaxValidation'=>false,
)); ?>
<?php $this->widget('zii.widgets.grid.CGridView',
array( 'id'=>'grid-id',
'dataProvider'=>$dataProvider, // or $model->search()
'filter'=>$model,
'columns'=>array(
array( 'name'=>'id',
'class'=>'CDataColumn',
'type'=>'raw',
'value'=>'CHtml::activeTextField($data, \'id\', array(\'readonly\'=>\'readonly\'))',
),
array( 'name'=>'item_name',
'class'=>'CDataColumn',
'type'=>'raw',
'value'=>'CHtml::activeTextField($data, \'item_name\')',
),
/*
rest of columns was here
*/
array( 'class'=>'CButtonColumn',
),
),
));
echo CHtml::submitButton('Update');
$this->endWidget();
?>
Action from controller:
public function actionView()
{
$dataProvider = new CActiveDataProvider('Item',
array(
'pagination'=>array(
'pageSize'=>10,
),
)
);
$model = new Item('search');
$model->unsetAttributes();
if (isset($_GET['Item']))
$model->attributes=$_GET['Item'];
$this->render('view', array(
'model'=>$model, 'dataProvider'=>$dataProvider,
));
}
There is no saving data yet, becouse it doesnt send what i need.
I’ll be greatfull for good ideas how to make it work (-> send all items from grid in POST).