Mirage
Mirage

Reputation: 31548

How to clear session variables in symfony2

I am setting session variable with this

$session->get('user_id');

I want to clear all session data or single variable. How can i do that

Upvotes: 28

Views: 49671

Answers (2)

NHG
NHG

Reputation: 5877

To clear all session data (attributes) you should use clear. Example:

$session->clear();

Please also see Symfony session attributes documentation.

Upvotes: 11

gaurang171
gaurang171

Reputation: 9080

Visit this link

http://api.symfony.com/master/Symfony/Component/HttpFoundation/Session/Session.html#remove%28%29

$session->remove('user_id');

Upvotes: 50

Related Questions