/** * 创建用户 * @return Ambigous <string, string> */ public function actionCreate() { $modelf = new UserForm(); $modelf->scenario = 'create'; if (!$modelf->load(Yii::$app->request->post(), '') || !$modelf->validate()) { return $this->renderContent(json_encode(array('code' => 102, 'message' => '验证失败'))); } if ($modelf->existUsername()) { return $this->renderContent(json_encode(array('code' => 107, 'message' => '用户名已存在'))); } $model = new User(); $model->password = $modelf->password; $model->username = $modelf->username; $model->project = $modelf->project; $model->department = $modelf->department; $model->qq = $modelf->qq; if (!$model->save()) { return $this->renderContent(json_encode(array('code' => 201, 'message' => '创建失败'))); } return $this->renderContent(json_encode(array('success' => true))); }