Skip to content

Commit de23479

Browse files
committed
Rewords and reorganization
1 parent 4063283 commit de23479

File tree

2 files changed

+24
-37
lines changed

2 files changed

+24
-37
lines changed

session.rst

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,41 @@ controllers if you type-hint an argument with
151151
// gets an attribute by name
152152
$foo = $session->get('foo');
153153

154-
// uses a default value if the attribute doesn't exist
154+
// the second argument is the value returned when the attribute doesn't exist
155155
$filters = $session->get('filters', []);
156156

157157
// ...
158158
}
159159
}
160160

161-
Stored attributes remain in the session for the remainder of that user's session.
162-
163161
.. tip::
164162

165163
Every ``SessionInterface`` implementation is supported. If you have your
166164
own implementation, type-hint this in the argument instead.
167165

166+
Stored attributes remain in the session for the remainder of that user's session.
167+
By default, session attributes are key-value pairs managed with the
168+
:class:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\AttributeBag`
169+
class.
170+
171+
If your application needs are complex, you may prefer to use
172+
:ref:`namespaced session attributes <namespaced-attributes>` which are managed with the
173+
:class:`Symfony\\Component\\HttpFoundation\\Session\\Attribute\\NamespacedAttributeBag`
174+
class. Before using them, override the ``session`` service definition to replace
175+
the default ``AttributeBag`` by the ``NamespacedAttributeBag``:
176+
177+
.. configuration-block::
178+
179+
.. code-block:: yaml
180+
181+
# config/services.yaml
182+
session:
183+
class: Symfony\Component\HttpFoundation\Session\Session
184+
arguments: ['@session.storage', '@session.namespacedattributebag', '@session.flash_bag']
185+
186+
session.namespacedattributebag:
187+
class: Symfony\Component\HttpFoundation\Session\Attribute\NamespacedAttributeBag
188+
168189
.. _session-avoid-start:
169190

170191
Avoid Starting Sessions for Anonymous Users
@@ -201,6 +222,5 @@ More about Sessions
201222
session/locale_sticky_session
202223
session/php_bridge
203224
session/proxy_examples
204-
session/attribute_bag
205225

206226
.. _`HttpFoundation component`: https://symfony.com/components/HttpFoundation

session/attribute_bag.rst

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)