aja*_*ybc 2 php yii yii-components
我正在Yii建立一个网站,我被困在用户身份验证步骤.无论我做什么,我都无法验证用户身份或在会话中存储一些价值.
我的UserIdentity组件如下:
class UserIdentity extends CUserIdentity
{
private $_id;
public function authenticate(){
if(($userRecord = Admin::model()->findByAttributes(array('username'=>$this->username)))===null){
return $this->errorCode=self::ERROR_USERNAME_INVALID;
}
if($userRecord->password!=hash('sha256', $this->password)){
return $this->errorCode=self::ERROR_PASSWORD_INVALID;
}
$this->_id=$userRecord->id;
$this->setState('title', $userRecord->username);
Yii::app()->session['clientId'] = $userRecord->clientId;
Yii::app()->session['id'] = $userRecord->id;
Yii::app()->session['loggedin'] = true;
return $this->errorCode=self::ERROR_NONE;
}
public function getId(){
return $this->_id;
}
}
Run Code Online (Sandbox Code Playgroud)
我Yii:app()->user->isGuest总是返回true并且Yii::app()->user->id什么都不返回.
这就是我尝试使用Yii::app()->session['loggedin']身份验证的原因.但即使这样也行不通.当我像这样访问会话数组时,Yii::app()->session我得到了错误Property "CWebUser.session" is not defined..
这真的令人沮丧.我是Yii的新手.请帮忙.