Hi again. I need your opinion on how to save a custom multi select to a database. I’m using jmultiselect2side extension and it is exactly what I need. i just don’t know how to save the selected values in the database and comma seperated ex.store,store2,store3 in my store column.
Help me veterans I had done this in my “made_from_scratch” application I just don’t know how to replicate it in yii.
For the comma separated list use explode() to throw them into an array.
I am assuming that you want to save the same posted data for each "store" in you comma separated list. Not sure how your code looks, so will make it up as I go:
$data_array = explode(",", $_POST['store_ids']);
foreach($data_array as $val) {
$model = new MyModel;
$model->store_id = $val;
// add whatever other $_POST data needs to be saved
$model->save();
}
hehe thanks sir do i put that in the controller of the model? in the actionCreate function? thanks again
public function actionCreate()
{
$model=new Store;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Store']))
{
$model->attributes=$_POST['Store'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}