/** * @return string|\yii\web\Response */ public function actionIndex() { $accountModel = new AccountForm(); $accountModel->setUser(Yii::$app->user->identity); $model = new MultiModel(['models' => ['account' => $accountModel, 'profile' => Yii::$app->user->identity->userProfile]]); return $this->render('index', ['model' => $model]); }
/** * @return string|\yii\web\Response */ public function actionIndex() { $accountModel = new AccountForm(); $accountModel->setUser(Yii::$app->user->identity); $model = new MultiModel(['models' => ['account' => $accountModel, 'profile' => Yii::$app->user->identity->userProfile]]); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-success'], 'body' => Yii::t('frontend', 'Your account has been successfully saved')]); return $this->refresh(); } return $this->render('index', ['model' => $model]); }
/** * Displays a single User model. * @return string|Response * @throws \yii\base\InvalidConfigException */ public function actionAccount() { /** @var SettingsForm $model */ $model = Yii::createObject(AccountForm::className()); $this->performAjaxValidation($model); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', '您的用户信息修改成功'); return $this->refresh(); } return $this->render('account', ['model' => $model]); }
/** * Performs ajax validation. * @param AccountForm $model * @throws \yii\base\ExitException */ protected function performAjaxValidation($model) { if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; echo json_encode(ActiveForm::validate($model)); Yii::$app->end(); } }