Пример #1
0
 /**
  * Creates a new Photos model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Photos();
     if ($model->load(Yii::$app->request->post())) {
         $model->shared_with = implode(',', $model->shared_with);
         $file = UploadedFile::getInstances($model, 'filename');
         foreach ($file as $filename) {
             $model1 = new Photos();
             $model1->user_id = Yii::$app->user->id;
             $model1->shared_with = $model->shared_with;
             $model1->filename = date("Ymdhis") . $filename->name;
             $path = Yii::getAlias('@uploads/albums/' . $model1->filename);
             if ($model1->save()) {
                 $filename->saveAs($path);
                 Image::thumbnail($path, 120, 120)->save(Yii::getAlias('@uploads/albums/thumbs/' . $model1->filename), ['quality' => 50]);
             }
         }
         Yii::$app->session->setFlash('success', 'Photos successfully posted.');
         Yii::$app->notification->notify($model1->filename, $model1, $model1->user, Yii::$app->controller->id, $model1->shared_with);
         $this->redirect('index');
     } else {
         if (Yii::$app->request->isAjax) {
             return $this->renderAjax('_form', ['model' => $model]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }
Пример #2
0
 /**
  * Creates a new Photos model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($event = null)
 {
     $model = new Photos();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->event_id = $event;
         $model->save();
         return $this->redirect(['/admin/events/view', 'id' => $event]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #3
0
 /**
  * Creates a new Photos model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreatePhoto()
 {
     $model = new Photos();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id_posts, "#" => 'photos']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }