Reputation: 1831
I have implemented a login screen. I understand how identity works. I can read user info from identity like this:
Yii::$app->user->identity->firstname
Has Yii a way to update identity info, in case user update his/her name on profile?
I have been checking the code, and I see Yii triggers an event to set the web/user identity:
$event = new UserEvent([
'identity' => $identity,
]);
$this->trigger(self::EVENT_BEFORE_LOGOUT, $event);
So since Identity is an instance of User maybe I could do:
$event = new UserEvent([
'identity' => $identity,
]);
$this->trigger('afterSave', $event);
Any security issues could bring this? any other ways to do it?
UPDATE I have found a method called "setIdentity":
http://www.yiiframework.com/doc-2.0/yii-web-user.html#setIdentity%28%29-detail
I will try it and see if it is what I am looking for.
Upvotes: 3
Views: 1786
Reputation: 1831
At the end the answer was easier than I thought. It updates automatically!!! when you update the user. In any case it was useful to learn something new. In Yii 1 worked different that was the cause of my confusion. Thanks for the help.
Upvotes: 1