The session component provides object-oriented wrappers to access session data.
Reasons to use this component instead of raw-sessions:
Starting the Session
Some applications are session-intensive, almost any action that performs requires access to session data. There are others who access session data casually. Thanks to the service container, we can ensure that the session is accessed only when it’s clearly needed:
Sometimes a user can use the same application twice, on the same server, in the same session. Surely, if we use variables in session, we want that every application have separate session data (even though the same code and same variable names). To solve this, you can add a prefix for every session variable created in a certain application:
Phalcon\Session\Bag is a component that helps separating session data into namespaces. Working by this way you can easily create groups of session variables into the application. By only setting the variables in the bag, it’s automatically stored in session:
Controller, components and classes that extends Phalcon\Di\Injectable may inject a Phalcon\Session\Bag. This class isolates variables for every class. Thanks to this you can persist data between requests in every class in an independent way.