L
L
lolka022022-04-07 15:39:42
PHP
lolka02, 2022-04-07 15:39:42

How to set up composite forms in Yii2?

I follow the instructions as here https://github.com/ElisDN/yii2-composite-form

class EditForm extends CompositeForm
{
public function __construct(int $moduleID, $config = [])
{
....
$ageModels = ChildrenAges::find()->all();

        $this->ages = array_map(function (ChildrenAges $ageModel) {
            return new AgeForm($ageModel);
        }, $ageModels);
....
}
....

    protected function internalForms()
    {
        return ['ages'];
    }
}


when editing, all records are inserted into the fields, but when adding new records
after
if (request()->isPost && $model->load(request()->post()) && $model->validate()) {

$model->ages is empty even though there is
AgeForm data in $_POST => [
0 => [...],
1 => [...]
]

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question