public function actionUpdate($id)
{
$model = Admin::findOne($id);
if (!$model) {
throw new NotFoundHttpException('未找到该后台用户。');
}
$model->load(Yii::$app->request->post());
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if (Yii::$app->request->isPost && $model->validate()) {
if (!empty($model->password)) {
$model->setPassword($model->password);
}
if ($model->save(false)) {
Yii::$app->session->setFlash('success', '成功更新后台用户“' . $model->username . '”。');
return $this->refresh();
} else {
Yii::$app->session->setFlash('danger', '更新后台用户失败。');
}
}
return $this->render('form', ['model' => $model]);
}