Exemplo n.º 1
0
 /**
  * Updates an existing Skill model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $model->scenario = 'update';
     if ($model->load(Yii::$app->request->post())) {
         $oldImg = $model->image;
         $old_parents = $model->parents;
         MyModel::upload($model);
         if ($model->save()) {
             MyModel::updateParents($model);
             MyModel::updateChildParents($model, $old_parents);
             if ($oldImg != $model->image && $model->image != '') {
                 MyModel::deleteFile($oldImg);
             }
             return $this->redirect(['view', 'id' => $model->id]);
         }
         return $this->render('update', ['model' => $model]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }