コード例 #1
0
 /**
  * Updates an existing User Photo.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdatephoto($id)
 {
     if ($id == \Yii::$app->user->id) {
         $model = $this->findModel($id);
         if ($model->load(Yii::$app->request->post())) {
             $image = UploadedFile::getInstance($model, 'photo_name');
             $model->photo_name = $image->name;
             if ($image != null) {
                 $imagePath = explode("\\", $image->tempName);
                 array_pop($imagePath);
                 $imagePath = implode("\\", $imagePath);
                 $imagePath = $imagePath . "\\" . $image->name;
                 $image->saveAs($imagePath);
                 $model->attachImage($imagePath, true);
             } else {
                 $model->removeImage($model->getImage(), true);
             }
             $change = new NotifUserHelper();
             $followersNotified = $change->userChangedPhoto($id);
             $model->save();
             return $this->redirect(['index', 'followersNotified' => $followersNotified]);
         } else {
             return $this->render('updatephoto', ['model' => $model]);
         }
     }
     return $this->redirect('index');
 }