Life Hacker Life Hacker - 5 months ago 28
PHP Question

Yii Unset Session

I have a

Session variable
in yii which corresponds to the particular user state

Yii::app()->user->setState('mycustomvar', 550);


So that I could get this variable as

Yii::app()->user->mycustomvar


How can I
unset
only this variable?

I got a solution Like this

Yii::app()->session->remove(Yii::app()->user->getStateKeyPrefix() . 'mycustomvar');


Is this a right way to do it?

Answer

I finally ran into a solution by using this

Yii::app()->session->remove(Yii::app()->user->getStateKeyPrefix() . 'mycustomvar');