Batch Insert / Update

i have "phone" model

and i want that we can make multi phone in one action

anyone knows how to setup it (view, controller)

now i hard coded for only 3phones in my _form:




<div class="form-group field-phone-phonenumber">

        <?= Html::activeLabel($phones[0], 'PhoneNumber', ['class' => 'col-lg-2 control-label']) ?>

        <div class="col-lg-3">

            <?= Html::activeDropDownList($phones[0], 'PhoneType', 

                ['Home' => 'Home', 'Office' => 'Office', 'Handphone' => 'Handphone'], 

                ['class' => 'form-control', 'prompt' => 'Select Telephone...']) ?>

        </div>

        <div class="col-lg-3">

            <?= Html::activeTextInput($phones[0], 'PhoneNumber', ['class' => 'form-control']) ?>

        </div>

    </div>

    

    <div class="form-group field-phone-phonenumber">

        <?= Html::activeLabel($phones[1], 'PhoneNumber', ['class' => 'col-lg-2 control-label']) ?>

        <div class="col-lg-3">

            <?= Html::activeDropDownList($phones[1], 'PhoneType', 

                ['Home' => 'Home', 'Office' => 'Office', 'Handphone' => 'Handphone'], 

                ['class' => 'form-control', 'prompt' => 'Select Telephone...']) ?>

        </div>

        <div class="col-lg-3">

            <?= Html::activeTextInput($phones[1], 'PhoneNumber', ['class' => 'form-control']) ?>

        </div>

    </div>

    

    <div class="form-group field-phone-phonenumber">

        <?= Html::activeLabel($phones[2], 'PhoneNumber', ['class' => 'col-lg-2 control-label']) ?>

        <div class="col-lg-3">

            <?= Html::activeDropDownList($phones[2], 'PhoneType', 

                ['Home' => 'Home', 'Office' => 'Office', 'Handphone' => 'Handphone'], 

                ['class' => 'form-control', 'prompt' => 'Select Telephone...']) ?>

        </div>

        <div class="col-lg-3">

            <?= Html::activeTextInput($phones[2], 'PhoneNumber', ['class' => 'form-control']) ?>

        </div>

    </div>



i can’t figure it out how yii2 to post data

and how to get data

Have you looked at your db structure… i.e. a master detail table relationship? Something like Customer and Phone … where Phone contains a customer_id foreign key to Customer?

If you already have that… you may consider looking at tabular forms to collect data for multiple phones for the customer_id in one single controller action. The link is for Yii 1.x, but you could use the same analogy for Yii 2 with not much changes.