new to yii2. How to save related models? I want to populate two tables with 1 form. what is the proper way in yii2.thx
new to yii2. How to save related models? I want to populate two tables with 1 form. what is the proper way in yii2.thx
if ($model->load(Yii::$app->getRequest()->post()) && $model->save()) {
if (Model::loadMultiple($lessons, Yii::$app->getRequest()->post()) && Model::validateMultiple($lessons)) {
foreach ($lessons as $lesson) {
$lesson->group_id = $model->id;
$lesson->save(false);
}
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', ['model' => $model, 'lessons' => $lessons]);
}