Dropdown Multiselect Values How To Save


public function actionCreate()

{

$model=new ExMusclesDetails;


// Uncomment the following line if AJAX validation is needed

// $this->performAjaxValidation($model);

if(isset($_POST['ExMusclesDetails']))

{


$_POST['ExMusclesDetails']['targeted_muscles']=serialize($_POST['ExMusclesDetails']['targeted_muscles']); 


$_POST['ExMusclesDetails']['additional_muscles']=serialize($_POST['ExMusclesDetails']['additional_muscles']);




$model->attributes=$_POST['ExMusclesDetails'];


$model->save(); 

$this->redirect(array('view','id'=>$model->id));

}


$this->render('create',array(

'model'=>$model,

));

}

thank you sir ,i solved that problems

:) :)

i solved the dropdown multiselect option

good :) how?

murugangm,

If you got a good way to store an array into a single field., it’s better to share here.

You need to examine your relational data and make the appropriate changes to your schema. See example below for a reference to this approach.

If you must save the array into a single field then the serialize() and unserialize() functions will do the trick. But you cannot perform queries on the actual content.

As an alternative to the serialization function there is also json_encode() and json_decode().

I also like very simple way which is implode() and explode(), if you listdata values are all numbers, and no groups. It will save the data like "1,2,3", not like serialized data "a:3:{i:0;s:1;…}", thus you can perform queries easily on actual content as you want.

And I also suggest you put serialize/implode in beforeSave(), and unserialize/explode in afterFind(), thus you can still use validation rules, and also allow both create and update actions when you save the data into database.