A
A
Arthur2015-10-07 22:14:52
Yii
Arthur, 2015-10-07 22:14:52

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

1 answer(s)
V
Viktor, 2015-11-06
@lxShaDoWxl

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 question

Ask a Question

731 491 924 answers to any question