/** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'view' page. * * @return mixed */ public function actionCreate() { $model = new User(); if ($model->load($_POST) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionSignup() { $model = new User(); $model->setScenario('signup'); if ($model->load($_POST) && $model->save()) { if (Yii::$app->getUser()->login($model)) { return $this->goHome(); } } return $this->render('signup', ['model' => $model]); }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { return $user; } } return null; }
public function actionSignup() { $model = new User(); // 初始化用户模型 $model->setScenario('signup'); // 设置场景为注册 if ($model->load($_POST) && $model->save()) { if ($model->sendSignupEmail($model)) { Yii::$app->getSession()->setFlash('signup', Yii::t('auth.user', 'Thank you for your registration. Please check your email.')); } else { Yii::$app->getSession()->setFlash('signup', Yii::t('auth.user', 'Error on sending email, Please contact the webmaster')); } } // 注册用户表单 return $this->render('signup', ['model' => $model]); }