Hello Yii lovers,
I face problem of rendering a form in a view.
At first my view should be displayed like this
4452
then, if user clicks one of the Name in the table, there will be generated a form like this
4453
There are 3 data in the table, but whatever I click, it still displays the same id…
For example, if I click the 137 Refreshing Guest Room, the right form displays detailed data of 137 Refreshing Guest Room.
It also only displays detailed data of 137 Refreshing Guest Room when I click the 1 Swimming Pool.
It is because this line
12 is the id of Refreshing Guest Room.
I wanna grab dynamic id from selected data, but it has no result.
If I change ‘model’=>$this->loadModel(12),
into
‘model’=>$this->loadModel($data->id),, it will result error => Undefined variable: data.
It’s sure because the above line is outside the cgridview widget.
As the cgridview successful to display, there is no problem in $dataprovider. I’ve already define $dataProvider in my controller. So what should I do to grab id of selected row?
These are full codes in my view
<?php Yii::app()->clientScript->registerScript('view', "
$('.edit-button').click(function(){
$('.edit-form').toggle();
return false;
});
$('.edit-form form').submit(function(){
$.fn.yiiGridView.update('facility-grid', {
data: $(this).serialize()
});
return false;
});
");
?>
<div class="row">
<div class="small-6 columns">
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'facility-grid',
'dataProvider'=>$dataProvider,
'template'=>"{items}",
'columns'=>array(
array('name'=>'id','header'=>'Name', 'type'=>'raw','value'=>'CHtml::link(CHtml::encode($data->quantity . " " . $data->name),array("#","id"=>$data->id),array("class"=>"edit-button"))'),
'description',
),
));
?>
</div>
<div class="small-6 columns">
<div class="edit-form" style="display:none">
<?php $this->renderPartial('_ajax_form_disable',array(
'model'=>$this->loadModel(12),
)); ?>
</div>
</div>
</div>
Thanks for your attention ^^