Blog tutorial and Yii::app()->user

Hello,

There is something i don’t understand in the blog tutorial.

In there … http://www.yiiframework.com/doc/blog/1.1/en/prototype.auth it is said :

"Both the username and id properties will be stored in the user session and may be accessed via Yii::app()->user from anywhere in our code."

It is because we redefine the getId() to return the id of the user and because there also the parent getId which return the username ? its unclear.

Thanks.

Hi,

You can access username and id this way:




Yii::app()->user->id;

Yii::app()->user->name;



But when you create a new UserIdentity($username, $password) instance, it doesn’t know anything about user id. So both commands above will return the same value ($username).

If you want to store user id, you should override the getId() method to return what you need. But it’s optional :)