Hi Experts,
I'm trying to store tabular input values in my model. I'm using only one model. I need to store in my model. but only last record is getting changed not all the records
can any one pls tell me why its happening only to last record. I'm also getting same page twice in my batchupdate.php file
my code is like this:
controller:
my view file batchupdate.php is:
Thanks in advance
I'm trying to store tabular input values in my model. I'm using only one model. I need to store in my model. but only last record is getting changed not all the records
can any one pls tell me why its happening only to last record. I'm also getting same page twice in my batchupdate.php file
my code is like this:
controller:
public function actionBatchUpdate() { $item = new Model; $items=Model::model()->findAll(); if(isset($_POST['Model'])) { $valid=true; foreach($items as $i=>$item) { if(isset($_POST['Model'][$i])) $item->attributes=$_POST['Model'][$i]; $valid=$item->validate() && $valid; } //print_r($item);die; if($valid){ if($item->save())$this->render('batchUpdate',array( 'items'=>$items)); } } // displays the view to collect tabular input $this->render('batchUpdate',array( 'items'=>$items)); }
my view file batchupdate.php is:
<div class="form"> <?php echo CHtml::beginForm(); ?> <table> <?php foreach($items as $i=>$item): ?> <tr style=" border-bottom: solid 1px black;"> <p><td><?php echo CHtml::activeTextField($item,"[$i]name",$htmlOptions=array('disabled'=>'disabled')); ?></td></p> </tr> <tr style=" border-bottom: solid 2px black;"> <p><td><?php echo CHtml::activeTextArea($item,"[$i]text",$htmlOptions=array ('rows'=>8,'cols'=>60));?></td></p></tr> <tr style=" border-bottom: solid 1px black;"> <p><td><?php echo CHtml::submitButton('Save');?></td></p></tr> <tr> <td><hr size="10" width="100%" /></td> </tr> <?php endforeach; ?> </table> <?php echo CHtml::endForm(); ?> </div><!-- form -->
Thanks in advance