我做了這個代碼教程:類的UserIdentity不返回性能Yii中
class UserIdentity extends CUserIdentity
{
private $_id;
private $_email;
public function authenticate()
{
$user=User::model()->findByAttributes(array('username'=>$this->username));
if($user===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if($user->password!==md5($this->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$user->id;
$this->_email=$user->email;
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
public function getId()
{
return $this->_id;
}
}
,我要儘量保存用戶的那個ID,但它不會返回ID,它返回emailadres,和當調用它時,電子郵件沒有定義:
echo Yii::app()->user->email;
請幫幫我!我新來Yii!
所以當使用'Yii :: app() - > user-> id'時,你會收到電子郵件地址?它是否正確?當調用'Yii :: app() - > user-> email'時,你會得到未定義的或空白的結果? – 2014-11-04 16:46:43
@TheHumbleRat是的,這是真的。奇怪是不是? – Refilon 2014-11-04 20:06:58