Se hai N modelli da salvare ti crei un array $items con N modelli vuoti, poi usi una cosa tipo questa
...
if (Model::loadMultiple($items, Yii::$app->request->post()) && Model::validateMultiple($items)) {
$count = 0;
foreach ($items as $item) {
// populate and save records for each model
if ($item->save()) {
// do something here after saving
$count++;
}
}
Yii::$app->session->setFlash('success', "Processed {$count} records successfully.");
return $this->redirect(['index']); // redirect to your next desired page
} else {
return $this->render('update', [
'items' => $items,
]);
}
$count = count(Yii::$app->request->post('competenze', []));
$competenze = [new CrCompetenza()];
for($i = 1; $i < $count; $i++) {
$competenze[$i] = new CrCompetenza();
}
if ( Model::loadMultiple($competenze, Yii::$app->request->post()) && Model::validateMultiple($competenze) ) {
foreach ($competenze as $competenza) {
// populate and save records for each model
if ($competenza->save(false)) {
// do something here after saving
$count++;
}
}
return $this->redirect(['curriculum/altreinfo']);
}