public function afterSave($event) { if ($this->owner->isNewRecord && ($tmpId = $this->getTmpId())) { if ($this->owner instanceof DaInstance) { $finder = $this->owner; } else { $finder = $this->owner->model(); } if ($this->resetScope) { $finder->resetScope(); } $model = $finder->findByIdInstance($this->owner->getIdInstance()); foreach ($this->getFiles() as $files) { foreach ($files as $file) { $modelDir = $model->getDir(true); $file->file_path = $modelDir . $file->getName(); $file->id_instance = $model->getIdInstance(); $file->id_tmp = null; $file->save(false); } } if (count($this->getFiles()) > 0) { //переносим файлы $mpDir = Yii::getPathOfAlias('temp') . '/' . $this->getTmpId(); HFile::copyDirectory($mpDir, $model->getDir(true, true)); HFile::removeDirectoryRecursive($mpDir, true); } } }