public function actionAdd() { $model = new Building(); if ($model->load(Yii::$app->request->post())) { if ($model->save()) { Yii::$app->session->setFlash('success', '成功添加学校建筑“' . $model->name . '”。'); return $this->redirect(['index']); } else { Yii::$app->session->setFlash('danger', '添加学校建筑失败。'); } } return $this->render('form', ['model' => $model]); }
/** * Creates a new Building model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Building(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $result = $this->redirect(['view', 'id' => $model->id]); } else { $model->loadDefaultValues(); $model->name = 'New Building'; $model->description = 'Building Description'; $result = $this->render('create', ['model' => $model]); } return $result; }