S
S
Sergey2015-03-30 01:39:25
Yii
Sergey, 2015-03-30 01:39:25

How to make yii2 form with one field and two models?

Hi all.
So I have two tables user, history.
When registering, the data is added to the user table, and I also need that when adding data to username, they are saved to the history table

<?php $form = ActiveForm::begin(['id' => 'form-signup']); ?>
<?= $form->field($model, 'username') ?>
<?= $form->field($model, 'password')->passwordInput() ?>

<?= Html::submitButton(Yii::t('frontend', 'Signup'), ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?>

Where should you look? in the form to change something? Customize behavior? Or AfterSave, BeforeSave? The request is desirable to throw off an example.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
index0h, 2015-03-30
@index0h

Look towards the behavior + model for the history table. An old one for yii 1.1.x was lying around

R
Roman Frank, 2015-03-30
@Akellacom

Are you doing something like logging?
In this case, I would make a separate method and use it in models where AfterSave is needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question