@@ -226,11 +226,21 @@ have all the request information at your fingertips::
226
226
227
227
// retrieve GET and POST variables respectively
228
228
$request->query->get('foo');
229
- $request->request->get('bar');
229
+ $request->request->get('bar', 'default value if bar does not exist');
230
+
231
+ // retrieve SERVER variables
232
+ $request->server->get('HTTP_HOST');
230
233
231
234
// retrieves an instance of UploadedFile identified by foo
232
235
$request->files->get('foo');
233
236
237
+ // retrieve a COOKIE value
238
+ $request->cookies->get('PHPSESSID');
239
+
240
+ // retrieve an HTTP request header, with normalized, lowercase keys
241
+ $request->headers->get('host');
242
+ $request->headers->get('content_type');
243
+
234
244
$request->getMethod(); // GET, POST, PUT, DELETE, HEAD
235
245
$request->getLanguages(); // an array of languages the client accepts
236
246
@@ -239,6 +249,27 @@ you'll never need to worry about. For example, the ``isSecure()`` method
239
249
checks the *three * different values in PHP that can indicate whether or not
240
250
the user is connecting via a secured connection (i.e. ``https ``).
241
251
252
+ .. sidebar :: ParameterBags and Request attributes
253
+
254
+ As seen above, the ``$_GET `` and ``$_POST `` variables are accessible via
255
+ the public ``query `` and ``request `` properties respectively. Each of
256
+ these objects is a :class: `Symfony\\ Component\\ HttpFoundation\\ ParameterBag `
257
+ object, which has methods like
258
+ :method: `Symfony\\ Component\\ HttpFoundation\\ ParameterBag::get `,
259
+ :method: `Symfony\\ Component\\ HttpFoundation\\ ParameterBag::has `,
260
+ :method: `Symfony\\ Component\\ HttpFoundation\\ ParameterBag::all ` and more.
261
+ In fact, every public property used in the previous example is some instance
262
+ of the ParameterBag.
263
+
264
+ The Request class also has a public ``attributes `` property, which holds
265
+ special data related to how the application works internally. For the
266
+ Symfony2 framework, the ``attributes `` holds the values returned by the
267
+ matched route, like ``_controller ``, ``id `` (if you have an ``{id} ``
268
+ wildcard), and even the name of the matched route (``_route ``). The
269
+ ``attributes `` property exists entirely to be a place where you can
270
+ prepare and store context-specific information about the request.
271
+
272
+
242
273
Symfony also provides a ``Response `` class: a simple PHP representation of
243
274
an HTTP response message. This allows your application to use an object-oriented
244
275
interface to construct the response that needs to be returned to the client::
0 commit comments