Answer the question
In order to leave comments, you need to log in
Yii2. I can't add a file to a post via ActiveRecord, how can I implement it?
How to implement the same as here? https://github.com/yiisoft/yii2/blob/master/docs/g...
How can I make it write the file on create and not delete it on update with the ability to change? Killed all day and did not achieve this result.
Answer the question
In order to leave comments, you need to log in
So here you can, for example, if the file is selected, then it will be loaded, and if not, the old one will remain
$file=UploadedFile::getInstance($model, 'imageFile');
if($file &&$file instanceof UploadedFile){
$model->imageFile = $file;
if ($model->upload()) {
// file is uploaded successfully
return;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question