Create many table in one form

Hi.

I’ve problem. I don’t know how to create multiple table from one form.

My database looks like:

6934

database.png

I create one form with two forms for two models and work:

form:


<?php $form = ActiveForm::begin(); ?>


    <?= $form->field($model, 'description')->textInput(['maxlength' => true]) ?>


    <?= $form->field($model, 'dataplus')->textInput(['maxlength' => true]) ?>


    <?= $form->field($model, 'comments')->textInput(['maxlength' => true]) ?>


    <?= $form->field($model, 'effects')->textInput(['maxlength' => true]) ?>


    <?= $form->field($model, 'tips')->textInput() ?>


    <?= $form->field($model, 'status_ben')->textInput() ?>


    <?= $form->field($model, 'emplo')->textInput() ?>


    <?= $form->field($model, 'tecz')->textInput() ?>


    <?= $form->field($przyczynasz, 'Przyczyna_idPrzycz')->textInput() ?>


    <?= $form->field($przyczynasz, 'card_sz_id_card_sz')->textInput() ?>




action Create:




public function actionCreate()

    {

        $model = new CardSz();

        $przyczynasz = new PrzyczynaCardSz();


        if ($model->load(Yii::$app->request->post()) && $przyczynasz->load(Yii::$app->request->post()) && Model::validateMultiple([$model,$przyczynasz])) {

            $model->save(false);

            $przyczynasz->save(false);


            return $this->redirect(['view', 'id' => $model->id_card_sz]);

        } else {

            return $this->render('create', [

                'model' => $model,

                'przyczynasz' => $przyczynasz,

            ]);

        }

    }

Problem:

Now I want use chceckboxlist in form:


    <?= $form->field($przyczynasz, 'card_sz_id_card_sz')->checkboxList(\yii\helpers\ArrayHelper::map(\app\models\Przyczyna::find()->all(), 'idPrzycz', 'NamePrzycz')) ;?>



I do not know how to use the leaves in controler. How to create tables with the current id of the model and selected a checkbox.

For example: when I selected one chceckbox create "przyczyna_card_sz" one raw in table with id card_sz, when selected two chceckbox create "przyczyna_card_sz" two raw in table with id card_sz