esien
(Esien 0525)
September 23, 2011, 2:00am
1
Hi All. How to update a tabular input as the
public function loadModel($id)
{
$model=Evaluation::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
only get the first element of the input only.
esien
(Esien 0525)
September 23, 2011, 10:26am
2
I had solved it.
In Controller
public function actionUpdate()
{
$items=$this->getitemstoupdate(Yii::app()->user->id);
$valid=true;
foreach($items as $i=>$item)
{
if(isset($_POST['Evaluation'][$i]))
$item->attributes=$_POST['Evaluation'][$i];
$valid=$item->validate() && $valid;
if($valid)
{
$item->save(false);
}
}
$this->render('update',array(
'items'=>$items,
));
}
----------------------------------------------------
public function getitemstoupdate($user_id)
{
$model=Evaluation::model()->findAll('evaluation_userID='.$user_id.' AND evaluation_approve=0');
return $model;
}
In View
<?php foreach($items as $i=>$item){
echo $form->radioButtonList($item,"[$i]evaluation_mark",array('0'=>'0','1'=>'1','2'=>'2','3'=>'3','4'=>'4','5'=>'5'),array('separator' => " | ", 'labelOptions'=>array('style'=>'display:inline')));
echo $form->textField($item,"[$i]evaluation_comment"); ?>