How to delete a state in CWebUser ?

hi everyone,

i set a state in my application by using the :


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

i want to destroy this state in a way that when i do a :


Yii::app()->user->hasState('foo')

it must return me FALSE, that mean this state is completely destroyed.

In fact CWebUser has a method : clearStates() but i don’t want to clear other states.

is there a way to do it ?

@ karim gioca

read the doc : setState





public function setState($key,$value,$defaultValue=null)

{

    $key=$this->getStateKeyPrefix().$key;

    if($value===$defaultValue)

        unset($_SESSION[$key]);

    else

        $_SESSION[$key]=$value;

}






it seems that if you set the same $key as null it will be destroyed:




Yii::app()->user->setState('foo',null);




i was looking into that last week, and i don’t think there is. I actually reverted to using session, much simpler and full control without needing to rely in user.


Yii::app()->session['myVar']=$var;

@ yiqing95 :

Yes it works, in fact when puting :


Yii::app()->user->setState('foo',null);

the value is removed from session and completely destroyed.

Thanx guys !!