/**
  * Updates an existing Album model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param string $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if (isset(Yii::$app->request->post()['imageSort'])) {
             foreach (Yii::$app->request->post()['imageSort'] as $key => $sortOrder) {
                 AlbumImage::updateAll(['sort_order' => $sortOrder], ['id' => $key]);
             }
         }
         $albumImage = AlbumImage::find()->where(['album_id' => $id])->orderBy(['sort_order' => SORT_ASC])->one();
         if ($albumImage) {
             $model->image = $albumImage->image;
             $model->thumb = $albumImage->thumb;
             $model->save();
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }