Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session deletion in Symfony 1.4

How do I delete all session variables at once if they are not in Array?

PS I set them this way:

$this->getUser()->setAttribute('PayPalTransaction.hash', $request->getParameter('hash'));

Regards, Roman

like image 990
Roman Newaza Avatar asked Sep 20 '11 08:09

Roman Newaza


3 Answers

The sfUser class (which you get with $this->getUser()), keeps all it's attributes in a sfNamespacedParameterHolder. So the setAttribute() function on sfUser if merely a proxy to the sfNamespacedParameterHolder::setAttribute(). You can get the reference to this holder with sfUser::getAttributeHolder().

The sfNamespacedParameterHolder also has a function clear(), which clears all attributes.

So to clear all attributes, use: $this->getUser()->getAttributeHolder()->clear().

(Please note that you will still be authenticated (e.g. logged in) when you clear the attribute holder).

like image 57
Grad van Horck Avatar answered Nov 17 '22 10:11

Grad van Horck


Another way if you want to remove just one session variable not all of them is to use the following code

$this->getUser()->getAttributeHolder()->remove('att_name');

Again this will only remove one not all ... to clear all use the previous code by Grad

like image 8
IslamAlaa Avatar answered Nov 17 '22 10:11

IslamAlaa


To remove all attributes of a namespace :

$this->getUser()->getAttributeHolder()->removeNamespace('yournamespace');
like image 7
arsenik Avatar answered Nov 17 '22 09:11

arsenik