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