本文整理汇总了PHP中app\modules\user\models\User::setScenario方法的典型用法代码示例。如果您正苦于以下问题:PHP User::setScenario方法的具体用法?PHP User::setScenario怎么用?PHP User::setScenario使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\modules\user\models\User
的用法示例。
在下文中一共展示了User::setScenario方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signup
/**
* Signs user up.
*
* @return User|null the saved model or null if saving fails
*/
public function signup()
{
if ($this->validate() === true) {
$user = new User();
$user->setScenario('signup');
$user->username = $this->username;
$user->password = $this->password;
$user->email = $this->email;
$user->generateAuthKey();
if ($user->save() === false) {
return null;
}
return $user;
}
return null;
}
示例2: beforeSave
public function beforeSave($insert)
{
if ($this->scenario == 'registerUser') {
$password = Yii::$app->security->generateRandomString(10);
$user = new User();
$user->setScenario('signup');
$user->username = $this->email;
$user->email = $this->email;
$user->first_name = $this->first_name;
$user->last_name = $this->last_name;
$user->password = $password;
$user->generateAuthKey();
if ($user->save()) {
Yii::$app->mail->compose('new-user-in-order', ['user' => $user, 'password' => $password])->setFrom(Yii::$app->getModule('core')->emailConfig['mailFrom'])->setTo($this->email)->setSubject(Yii::t('app', 'Welcome to {appName}', ['appName' => Yii::$app->getModule('DefaultTheme')->siteName]))->send();
Yii::$app->user->login($user, 86400);
$this->user_id = $user->id;
}
}
return parent::beforeSave($insert);
}