Пример #1
0
 public function upload(FileInterface &$model, $attribute, $isPrivate = null)
 {
     $file = \yii\web\UploadedFile::getInstanceByName($attribute);
     $destination = $this->getDestinationFolder($model->getFolder(), $isPrivate);
     $destination .= DIRECTORY_SEPARATOR . $file->baseName . '.' . $file->extension;
     if (file_exists($destination) and File::findOne(['path' => $destination])) {
         $model = File::findOne(['path' => $destination]);
     } else {
         $model->setPath($destination);
         $model->setExtension($file->extension);
         $model->setSystemName($file->baseName);
     }
     if (!$file->saveAs($destination)) {
         return false;
     }
     return true;
 }
Пример #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getImages()
 {
     return $this->hasMany(File::className(), ['id' => 'image_id'])->viaTable('category_image', ['category_id' => 'id']);
 }