Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Yii::app()->user->name

Tags:

yii

I tried

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

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

like image 226
Luke Wenke Avatar asked Jan 09 '13 12:01

Luke Wenke


1 Answers

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

  • A complete example in the Yii guide
  • The setState() documentation
like image 149
darkheir Avatar answered Oct 12 '22 22:10

darkheir