我在Yii中使用setState,但我也获得属性;CWebUser.depId“;没有定义
我想从table user返回dep_id值以使用它,因此setState应该像(Yii::app()->user->depId)一样返回它,但是当我使用它时,我得到--“CWebUser.depId”没有定义。我搜索了一下,不知道该怎么办,我需要一个快速的答案这是我的 例如:我在Yii中使用setState,但我也获得属性;CWebUser.depId“;没有定义,yii,setstate,Yii,Setstate,我想从table user返回dep_id值以使用它,因此setState应该像(Yii::app()->user->depId)一样返回它,但是当我使用它时,我得到--“CWebUser.depId”没有定义。我搜索了一下,不知道该怎么办,我需要一个快速的答案这是我的 例如: private $_id; //private $_dep_id; public function authenticate() { $user=User::model()->find('LOWER(use
private $_id;
//private $_dep_id;
public function authenticate()
{
$user=User::model()->find('LOWER(username)=?',array(strtolower($this->username)));
if($user===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if(!$user->validatePassword($this->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$user->id;
$this->setState('depId',$user->dep_id);
$this->username=$user->username;
$this->setState('lastLogin', date("m/d/y g:i A", strtotime($user->last_login_time)));
$user->saveAttributes(array('last_login_time'=>date("Y-m-d H:i:s", time())));
$this->errorCode=self::ERROR_NONE;
}
return $this->errorCode==self::ERROR_NONE;
}
public function getId()
{
return $this->_id;
}
然后我得到了这个
Property "CWebUser.depId" is not defined.
这里有什么问题 您必须是经过身份验证的用户才能在上述场景中使用该变量,因为它仅限于经过身份验证的用户 当您调用
Yii::app()->user->depId
时,用户是否经过身份验证?dep_id是否是正确的列名?如果dep_id是您应该使用的列名Yii::app()->user->dep_id
如何确保用户经过身份验证?!如何才能做到这一点?!我认为您知道什么是经过身份验证的用户,因为您正在编写上面的代码来对用户进行身份验证。您的应用程序用户在登录后将使用web应用程序所需的有效凭据进行身份验证。