Yii2 dynamically created drop down list using foreach?

Hello, I need advice... Maybe even an explanation...
Guided by this article

In this view _form:
foreach ($tableFromTemplate as $index => $setting) {
 echo $form->field($setting, '[$index]id_table')->dropDownList(
 ArrayHelper::map($tableDesc, 'id', 'tag_table_desc')
 )->label(false);

in the foreach in the view _form when building the dom key is passed as [$index]... Accordingly, I cannot save the changed data....
foreach ($tableFromTemplate as $index => $setting) {
 echo $form->field($setting, "[$index]id_table")->label($setting->id_table);
} ?>

And as such, foreach without implementing drop-down list using the dropDownList, everything works, everything is saved, the key [$index]takes values in the dom is passed in [0],[1]...

Controller

public function actionUpdate($id)
{
$model = $this->findModel($id);

$tableDesc =TagTable::find()->asArray()->all();//array of table names

$idTemplate = $model->id;

$tableFromTemplate = TableFromTemplate::find()->where(['id_template' => $idTemplate])->indexBy('id')->all();//array of patterns for the editable template

if (Model::loadMultiple($tableFromTemplate, Yii::$app->request->post()) && Model::validateMultiple($tableFromTemplate)) {
foreach ($tableFromTemplate as $setting) {
$setting->save(false);
}
return $this->redirect(['view', 'id' => $model->id]);
}

if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
'category' => TemplateCategory::find()->all(),
'tableDesc' => $tableDesc,
'tableFromTemplate' => $tableFromTemplate
]);
}

}
April 19th 20 at 12:28
1 answer
April 19th 20 at 12:30
Solution
Look at your quotation marks
The certificate from Google

Find more questions by tags Yii