The form has a dropDownList for outputting data from the database as a drop-down list with multiple choices:
<?= $form->field($model, 'parts[]')->dropDownList($model->IngredientDropdown, ['multiple' => 'multiple'] ); ?> In the model:
public function getIngredientDropdown() { $listIngredient = Ingredient::find()->select('id,ititle')->all(); $list = ArrayHelper::map( $listIngredient, 'id', 'ititle'); return $list; } In the controller:
public function actionCreate() { $model = new Dish(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, ]); } } I ask to prompt how to save the selected data in the form of one entry separated by commas in the parts field in the parts field?