/**
  * Creates a new File model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new File();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#2
0
 /**
  * Loading group of files.
  * @return bool
  */
 public function loadFiles()
 {
     foreach ($this->files as $file) {
         $model = new File();
         $model->file = $file;
         $model->type = $this->type;
         $model->material_id = $this->material_id;
         $model->directory = $this->directory;
         $model->prefix = $this->prefix;
         $model->material_type = $this->material_type;
         $model->save();
     }
     return true;
 }
示例#3
0
 public function loadingMainImage()
 {
     if ($this->delete_main_image) {
         File::deleteFileModel($this->main_image_id);
     }
     $image = UploadedFile::getInstance($this, 'main_image');
     if ($image != null) {
         if ($this->main_image_id != null && $image !== null) {
             File::deleteFileModel($this->main_image_id);
         }
         $file = new File();
         $file->file = UploadedFile::getInstance($this, 'main_image');
         $file->type = File::TYPE_IMAGE;
         $file->material_id = $this->id;
         $file->directory = 'images/page/';
         $file->prefix = 'page';
         $file->material_type = File::MATERIAL_TYPE_PAGE;
         if ($file->save()) {
             $this->main_image_id = $file->id;
             return $this->save();
         } else {
             return false;
         }
     } else {
         return true;
     }
 }