本文整理匯總了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);
}