Example: Session in Examples for Developers 8
Same name and namespace in other branches
- 3.x modules/session_example/session_example.module \session_example
Demonstrating how to manipulate sessions in Drupal 8.
You can read the API documentation here: https://api.drupal.org/api/drupal/core%21core.api.php/group/session/
Drupal's session management is inherited from Symfony. We use the Symfony\Component\HttpFoundation\Session\SessionInterface object which we can get from the Request object.
This object allows us to get and set values from the user session.
We can use the session to store information per visitor.
In this example, we will have the user fill out a form with some personal information, and then be able to display that information on another page.
To learn more, one could examine the Stream Wrapper Example. It uses the session API to implement a session: file scheme.
See also
https://api.drupal.org/api/drupal/core%21core.api.php/group/session/
Parent topics
File
- session_example/
session_example.module, line 8 - Session example module demonstrates manipulating user sessions.
Classes
Name | Location | Description |
---|---|---|
SessionExampleController |
session_example/ |
Controller for a page to display the session information. |
SessionExampleForm |
session_example/ |
Form to allow the user to store information in their session. |
SessionExampleTest |
session_example/ |
Tests the basic functions of the Session Example module. |