Yii user setstate / getstate

I am using Yii framework and I want to use user setstate, getstate methods but found out some problems, please can you help me to solve them? here is my codes:


protected function afterLogin()


    Yii::app()->user->setState('username', $record->username);

    Yii::app()->user->setState('privilages', $record->privilages);


man layout

array('label'=>Yii::app()->user->getState('username'), 'url'=>array('/user/index'), 'visible'=>!Yii::app()->user->isGuest),

when user loges in it doesn’t show his username, it just show whitespaces. so can you tell me what is wrong with it?

how to authenticate against database and setting the username, you can see here


however, $record is not available in your afterLogin-method

Try this:

man layout

array('label'=>Yii::app()->user->username, 'url'=>array('/user/index'), 'visible'=>!Yii::app()->user->isGuest),

Change from Yii::app()->user->getState('username’) to Yii::app()->user->username

Remove what is in bold.

the function afterLogin know which is the variable $record? I dont see this in parameters. If this is global you need is $this->record


Can anyone explain how we can use it? /How to use it, I do not understand, confused. :(



Note: this is an old Yii 1.1 discussion.