Ejemplo n.º 1
0
 /**
  * Updates an existing Books model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $authors = Authors::getAuthorsForDropDownList();
     $model = $this->findModel($id);
     //Request from form
     if (Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->post());
         $model->cover = UploadedFile::getInstance($model, 'cover');
         if ($model->save()) {
             $absoluteUrl = Yii::$app->session->has('absoluteUrl') ? Yii::$app->session->get('absoluteUrl') : Yii::$app->urlManager->createUrl("books");
             return $this->redirect($absoluteUrl);
         }
     }
     //Render update form
     return $this->render('update', ['model' => $model, 'authors' => $authors]);
 }