@@ -206,7 +206,7 @@ allow you to interact with the HTTP request and response in an easier way.
206
206
Symfony Request Object
207
207
~~~~~~~~~~~~~~~~~~~~~~
208
208
209
- The :class: `Symfony\\ Component\\ HttpFoundation\\ Request ` class is a simple
209
+ The :class: `Symfony\\ Component\\ HttpFoundation\\ Request ` class is an
210
210
object-oriented representation of the HTTP request message. With it, you
211
211
have all the request information at your fingertips::
212
212
@@ -218,14 +218,14 @@ have all the request information at your fingertips::
218
218
$request->getPathInfo();
219
219
220
220
// retrieve $_GET and $_POST variables respectively
221
- $request->query->get('foo ');
222
- $request->request->get('bar ', 'default value if bar does not exist ');
221
+ $request->query->get('id ');
222
+ $request->request->get('category ', 'default category ');
223
223
224
224
// retrieve $_SERVER variables
225
225
$request->server->get('HTTP_HOST');
226
226
227
- // retrieves an instance of UploadedFile identified by foo
228
- $request->files->get('foo ');
227
+ // retrieves an instance of UploadedFile identified by "attachment"
228
+ $request->files->get('attachment ');
229
229
230
230
// retrieve a $_COOKIE value
231
231
$request->cookies->get('PHPSESSID');
@@ -234,36 +234,14 @@ have all the request information at your fingertips::
234
234
$request->headers->get('host');
235
235
$request->headers->get('content_type');
236
236
237
- $request->getMethod(); // GET, POST, PUT, DELETE, HEAD
237
+ $request->getMethod(); // e.g. GET, POST, PUT, DELETE or HEAD
238
238
$request->getLanguages(); // an array of languages the client accepts
239
239
240
240
As a bonus, the ``Request `` class does a lot of work in the background that
241
241
you'll never need to worry about. For example, the ``isSecure() `` method
242
242
checks the *three * different values in PHP that can indicate whether or not
243
243
the user is connecting via a secured connection (i.e. HTTPS).
244
244
245
- .. sidebar :: ParameterBags and Request Attributes
246
-
247
- As seen above, the ``$_GET `` and ``$_POST `` variables are accessible via
248
- the public ``query `` and ``request `` properties respectively. Each of
249
- these objects is a :class: `Symfony\\ Component\\ HttpFoundation\\ ParameterBag `
250
- object, which has methods like
251
- :method: `Symfony\\ Component\\ HttpFoundation\\ ParameterBag::get `,
252
- :method: `Symfony\\ Component\\ HttpFoundation\\ ParameterBag::has `,
253
- :method: `Symfony\\ Component\\ HttpFoundation\\ ParameterBag::all ` and more.
254
- In fact, every public property used in the previous example is some instance
255
- of the ParameterBag.
256
-
257
- .. _book-fundamentals-attributes :
258
-
259
- The Request class also has a public ``attributes `` property, which holds
260
- special data related to how the application works internally. For the
261
- Symfony Framework, the ``attributes `` holds the values returned by the
262
- matched route, like ``_controller ``, ``id `` (if you have an ``{id} ``
263
- wildcard), and even the name of the matched route (``_route ``). The
264
- ``attributes `` property exists entirely to be a place where you can
265
- prepare and store context-specific information about the request.
266
-
267
245
Symfony Response Object
268
246
~~~~~~~~~~~~~~~~~~~~~~~
269
247
@@ -285,20 +263,11 @@ needs to be returned to the client::
285
263
// print the HTTP headers followed by the content
286
264
$response->send();
287
265
288
- There are also special classes to make certain types of responses easier to create:
289
-
290
- * :ref: `JsonResponse <component-http-foundation-json-response >`;
291
-
292
- * :ref: `BinaryFileResponse <component-http-foundation-serving-files >` (for streaming
293
- files and sending file downloads);
294
-
295
- * :ref: `StreamedResponse <streaming-response >` (for streaming any other large responses);
296
-
297
266
.. tip ::
298
267
299
268
The ``Request `` and ``Response `` classes are part of a standalone component
300
269
called :doc: `symfony/http-foundation </components/http_foundation/introduction >`
301
- that yo can use in *any * PHP project. This also contains classes for handling
270
+ that you can use in *any * PHP project. This also contains classes for handling
302
271
sessions, file uploads and more.
303
272
304
273
If Symfony offered nothing else, you would already have a toolkit for easily
0 commit comments