public function actionUpdate($id)
 {
     $model = Building::findOne($id);
     if (!$model) {
         throw new NotFoundHttpException('未找到该学校建筑。');
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             Yii::$app->session->setFlash('success', '成功更新学校建筑“' . $model->name . '”。');
             return $this->refresh();
         } else {
             Yii::$app->session->setFlash('danger', '更新学校建筑失败。');
         }
     }
     return $this->render('form', ['model' => $model]);
 }
示例#2
0
 /**
  * Finds the Building model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Building the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Building::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }