本文整理汇总了PHP中yii\base\Model::getIdentity方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::getIdentity方法的具体用法?PHP Model::getIdentity怎么用?PHP Model::getIdentity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\base\Model
的用法示例。
在下文中一共展示了Model::getIdentity方法的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();
}