Пример #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new PropertyImages();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['PropertyImages'])) {
         $model->attributes = $_POST['PropertyImages'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Пример #2
0
 public static function addMultipleImage($propertyId, $images)
 {
     $count = 0;
     foreach ($images as $image) {
         $destinationFileName = ImageUtils::generateFileName(basename($image));
         $destinationFile = self::getImagesDirectory($propertyId) . $destinationFileName;
         $success = Yii::app()->s3->upload($image, $destinationFile, Yii::app()->params['s3BucketName']);
         if ($success) {
             $model = new PropertyImages();
             $model->property_id = $propertyId;
             $model->image = $destinationFileName;
             $model->save();
             $count++;
         }
     }
     return $count;
 }