Reputation: 1
I have problem when i go to the edit link from the admin page on the update page check boxes are not update shown .please guide me. Here is my view
<?php echo $form->checkBoxList($model, 'partecipants', array('Members'=>'Members','sites'=>'sites','packages'=>'packages',' Report'=>'Report'),array('class'=>'tst')); ?>
here is my controller
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Admin_user_groups']))
{
$model->attributes=$_POST['Admin_user_groups'];
if($model->save())
$this->redirect(array('view','id'=>$model->group_id));
}
$this->render('update',array(
'model'=>$model,
));
}
Upvotes: 0
Views: 4957
Reputation: 3823
If you saving checkboxes with coma in DB field then you need to make string from your array with implode:
if(isset($_POST['Admin_user_groups']))
{
$model->attributes=implode(',',$_POST['Admin_user_groups']);
if($model->save())
$this->redirect(array('view','id'=>$model->group_id));
}
Upvotes: 0
Reputation: 1053
while updating you should pass the participants as an array to the view i.e.
$model->participants = array(1,2,3,4) // this array contains the participants id.
For more checkout this link
http://www.yiiframework.com/forum/index.php/topic/41616-checkboxlist-checked-on-update-time/
Upvotes: 1