src/behaviors/File.php
public function processFiles($event = null)
    {
        /** @var Model $model */
        $model = $this->owner;
        $ids = [];

        if (in_array($model->scenario, $this->scenarios, true)) {
            $files = UploadedFile::getInstances($model, $this->attribute);

            foreach ($files as $file) {
                $model = $this->uploadFile($file);
                $ids[] = $model->id;
            }

            if (!empty($ids)) {
                $this->owner->{$this->targetAttribute} = implode(',', $ids);
            } else {
                // Protect attribute
                $model->{$this->attribute} = null;
            }
        }
    }
public function processFiles($event = null)
    {
        /** @var Model $model */
        $model = $this->owner;
        $ids = [];

        if (in_array($model->scenario, $this->scenarios, true)) {
            $files = UploadedFile::getInstances($model, $this->attribute);

            foreach ($files as $file) {
                $model = $this->uploadFile($file);
                $ids[] = $model->id;
            }

            if (!empty($ids)) {
                $this->owner->{$this->targetAttribute} = implode(',', $ids);
            } else {
                // Protect attribute
                $model->{$this->attribute} = null;
            }
        }
    }
public function processFiles ( $ event = null ) { /** @var Model $model */ $ model = $ this -> owner ; $ ids = [ ] ; if ( in_array ( $ model -> scenario , $ this -> scenarios , true ) ) { $ files = UploadedFile :: getInstances ( $ model , $ this -> attribute ) ; foreach ( $ files as $ file ) { $ model = $ this -> uploadFile ( $ file ) ; $ ids [ ] = $ model -> id ; } if ( ! empty ( $ ids ) ) { $ this -> owner -> { $ this -> targetAttribute } = implode ( ',' , $ ids ) ; } else { // Protect attribute $ model -> { $ this -> attribute } = null ; } } }
Event handler for beforeInsert and beforeUpdate actions.

@param \yii\base\ModelEvent $event
Event handler for beforeInsert and beforeUpdate actions .