Esempio n. 1
0
 protected function findModel($id)
 {
     $model = new BookForm();
     if ($model->loadBook($id) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Запрашиваемой страницы не существует.');
     }
 }
Esempio n. 2
0
 public function actionUpdate($id)
 {
     /** @var Book $book */
     $book = Book::findOne($id);
     $model = new BookForm();
     $model->loadBook($book);
     if (\Yii::$app->request->isGet) {
         return $this->render('form', ['model' => $model]);
     }
     if (\Yii::$app->request->isPost) {
         $book->setAttributes(\Yii::$app->request->post('BookForm'), false);
         if ($book->save()) {
             return $this->goBack();
         }
     }
     return $this->redirect('site/error');
 }