I use setState in Yii but i also get Property "CWebUser.depId" is not defined

StackOverflow https://stackoverflow.com/questions/20663177

  •  19-09-2022
  •  | 
  •  

質問

i want to return the value dep_id from table user to use it so setState is supposed to return it like (Yii::app()->user->depId) but when i use it i get -- "CWebUser.depId" is not defined. i searched and i dont know what to do and i need a quick answer this is my example:

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;
}

and then i get this

Property "CWebUser.depId" is not defined.

what is the problem here ?!

役に立ちましたか?

解決

You have to be authenticated user to use that variable on above scenario because it is restricted for authenticated users.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top