I have build a form in D8 and on submit I want to save the form values into a session, so that I can access them 3, 4,.... page requests later. In D7 I just used

$_SESSION['key'] = $value

I have a feeling, in D8 and symfony, this is (very) bad practice. How should I solve this? At the moment I'm using the following chunk of code, but I don't know if this is the correct way:

$session = new Session();
$session->set('name', 'value');

$name = $session->get('name');

1 Answer 1


The conversion to the Symfony session component is not yet complete, therefore you still have to access the session using the superglobal.

Follow https://www.drupal.org/node/1858196 and its sub-issues, if you like to stay up to date regarding this issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.