Form
<?=
$form->field($model, 'categories')
->dropDownList($model->CategoryDropdown,
[
'class'=>'chosen-select input-md required',
'multiple'=>'multiple'
]
)->label("Add Categories");
?>
Controller:
public function actionCreate(){
...
$model->categories = implode(",",$_POST['Company']['categories']);
...
return $this->render('create', [
'model' => $model,
]);
}
public function actionUpdate($id)
{
$model = $this->findModel($id);
$model->categories = explode(',', $model->categories);
...
if($model->load(Yii::$app->request->post()))
{
$model->categories = implode(",",$_POST['Company']['categories']);
...
$model->save()
}
return $this->render('update', [
'model' => $model,
]);
}
No comments:
Post a Comment