本文整理匯總了PHP中yii\base\Model::getNewCode方法的典型用法代碼示例。如果您正苦於以下問題:PHP Model::getNewCode方法的具體用法?PHP Model::getNewCode怎麽用?PHP Model::getNewCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yii\base\Model
的用法示例。
在下文中一共展示了Model::getNewCode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: sendEmail
/**
* Sends out an email containing instructions and link to the email verification
* or password recovery page, containing an activation key.
* @param \yii\base\Model $model it must have a getIdentity() method
* @param string $mode 'recovery', 'verify' or 'oneTimePassword'
* @return boolean if sending the email succeeded
*/
public function sendEmail(\yii\base\Model $model, $mode)
{
$params = ['siteUrl' => \yii\helpers\Url::toRoute(['/'], true)];
switch ($mode) {
default:
return false;
case 'recovery':
case 'verify':
$subject = $mode == 'recovery' ? Yii::t('usr', 'Password recovery') : Yii::t('usr', 'Email address verification');
$params['actionUrl'] = \yii\helpers\Url::toRoute([$this->module->id . '/default/' . $mode, 'activationKey' => $model->getIdentity()->getActivationKey(), 'username' => $model->getIdentity()->username], true);
break;
case 'oneTimePassword':
$subject = Yii::t('usr', 'One Time Password');
$params['code'] = $model->getNewCode();
break;
}
$message = Yii::$app->mailer->compose($mode, $params);
$message->setTo([$model->getIdentity()->getEmail() => $model->getIdentity()->username]);
$message->setSubject($subject);
return $message->send();
}