@@ -151,20 +151,41 @@ controllers if you type-hint an argument with
151
151
// gets an attribute by name
152
152
$foo = $session->get('foo');
153
153
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
155
155
$filters = $session->get('filters', []);
156
156
157
157
// ...
158
158
}
159
159
}
160
160
161
- Stored attributes remain in the session for the remainder of that user's session.
162
-
163
161
.. tip ::
164
162
165
163
Every ``SessionInterface `` implementation is supported. If you have your
166
164
own implementation, type-hint this in the argument instead.
167
165
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
+
168
189
.. _session-avoid-start :
169
190
170
191
Avoid Starting Sessions for Anonymous Users
@@ -201,6 +222,5 @@ More about Sessions
201
222
session/locale_sticky_session
202
223
session/php_bridge
203
224
session/proxy_examples
204
- session/attribute_bag
205
225
206
226
.. _`HttpFoundation component` : https://symfony.com/components/HttpFoundation
0 commit comments