【发布时间】:2013-12-18 16:18:55
【问题描述】:
我想从表用户返回值 dep_id 以使用它,因此 setState 应该像 (Yii::app()->user->depId) 一样返回它,但是当我使用它时,我得到 - “CWebUser. depId”未定义。我搜索了,我不知道该怎么做,我需要一个快速的答案这是我的 示例:
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是正确的列名吗? -
同意@veelen 大概是如果 dep_id 是您应该使用的列名
Yii::app()->user->dep_id -
如何确保用户已通过身份验证?!