Answer the question
In order to leave comments, you need to log in
Yii2 get ID of not yet created user?
There is a form for creating a user (full name, date of birth, phone number, photo).
Adding a photo was done only in update (because the user_id is known there):
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
echo $form->field($model_file, 'imageFile[]')->widget(
FileInput::classname(), [
'options' => ['multiple' => true],
'pluginOptions' => ['previewFileType' => 'any',
'uploadUrl' => Url::to(
['/users/upload?model_id=' . $model->id]
)],
]
);
ActiveForm::end();
Answer the question
In order to leave comments, you need to log in
Just load the photo in afterSave() where there is already an id
Maxim Timofeev parvily said, but sometimes, in some thread of complex business logic, there really is a need to get the id of an entity that has not yet been saved. To solve this problem, you need to abandon auto-increments in tables and get the id from some thread of the counter, for example, redis incr.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question