/** * Creates a new Admin model. * If creation is successful, the browser will be redirected to the 'view' page. * @throws UserError if this model generate errors. * @return mixed */ public function actionCreate() { $model = new Admin(); $model->scenario = 'create'; if ($this->isPost) { $model->attributes = $this->request->post($model->formName(), []); if ($model->save()) { if (Yii::$app->response->acceptMimeType == 'application/json') { return ['pk' => $model->id, 'data' => $model->toArray()]; } elseif (Yii::$app->response->acceptMimeType == 'text/grid') { return $this->search(['id' => $model->id]); } else { return $this->redirect(['index']); } } else { if ($this->isAjax) { throw new UserError($model->getErrors()); } else { goto REN; } } } else { REN: return $this->render('create', ['model' => $model, 'honors' => AdminRole::honorMap()]); } }