6

I tried

public function getName()
{
    return 'TEST';
}

in UserIdentity.php but it doesn't seem to change the value of Yii::app()->user->name

Luke Wenke
  • 1,149
  • 2
  • 23
  • 43
  • While this question is for Yii1, I wrote an answer for how to do it in Yii2 properly. Just in case anyone searching Google for this lands here, read this for Yii2: http://stackoverflow.com/questions/38415388/yii2-how-to-get-the-current-username-or-name-from-yiiapp-user – Wade Jul 16 '16 at 21:06

1 Answers1

11

In the class UserIdentity that you defined you'll need to set a new state by using setState(name, value) method.

For example in the method authenticate if the user is good:

//if the user is good (good login and good password)
$this->_id=$record->id;
$this->setState('name', $record->name);
$this->errorCode=self::ERROR_NONE;

Then you will be able to call Yii::app()->user->name

darkheir
  • 8,844
  • 6
  • 45
  • 66