I've a problem, it might be a small one but I couldn't find the solution for this. Yii:app()->user->getId() or Yii:app()->user->id is not returning value. it just returning empty result. But I've set the id in my UserIdentity class.
in my UserIdentity class I've this,
public function getId()
{
return $this->id;
}
I'm setting id in the autheticate() function. if i displayed there itself it's displaying the id, but not in getId() function. Please help me in this.
Thanks in advance.
Dhanendran Rajagopal.
Not sure if you are using the standard UserIdentity class, but in the standard one
id
is a private attribute and in Yii convention private attributes have_
in front of them, so it would be like this:Since it is private variable you can't access it with
Yii::app()->user->_id
. ThegetId()
function is a magic function, when you runYii::app()->user->id
, it sees there is noid
attribute so looks for a function namedgetId()
and runs it if it exists.If you are using the standard class you need to change this as you stated in your comment below:
Refactor your getId() function like this!
This problem begin when you set the user states in your Identity. You try to set state, and then get an attribute!