Делаю так...
Контролер:
public function actionUpdate($id)
{
$model = $this->findModel($id);
$sectionsList = EstimateSection::listOfSection($model->id);
foreach ($sectionsList as $section) {
$resources = new ActiveDataProvider([
'query' => EstimateResource::find()->where(['estimate_section_id' => $section->id])
]);
$sections[] = [
'section' => $section,
'resources' => $resources,
];
}
if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
return $this->render('update', [
'model' => $model,
'sections' => $sections
]);
}
return $this->render('update', [
'model' => $model,
'sections' => $sections
]);
}
public function actionAjaxCreateSection($estimate_id) {
$section = new EstimateSection();
$section->estimate_id = $estimate_id;
$section->save();
$resources = new ActiveDataProvider([
'query' => EstimateResource::find()->where(['estimate_section_id' => $section->id])
]);
return $this->renderAjax('_new_section', [
'resources' => $resources,
'section_id' => $section->id,
]);
}