@@ -202,18 +202,18 @@ to the controller:
202
202
return $collection;
203
203
204
204
Now, you can go to ``/hello/ryan `` (e.g. ``http://localhost:8000/app_dev.php/hello/ryan ``
205
- if you're using the :doc: `built-in web server </cookbook/webserver/built_in >`_ )
205
+ if you're using the :doc: `built-in web server </cookbook/webserver/built_in >`)
206
206
and Symfony will execute the ``HelloController::indexAction() `` controller
207
207
and pass in ``ryan `` for the ``$name `` variable. Creating a "page" means
208
- simply creating a controller method and associated route.
208
+ simply creating a controller method and an associated route.
209
209
210
210
Simple, right?
211
211
212
- .. sidebar :: The AppBundle:Hello:index syntax for YML and XML
212
+ .. sidebar :: The AppBundle:Hello:index controller syntax
213
213
214
214
If you use the YML or XML formats, you'll refer to the controller using
215
215
a special shortcut syntax: ``AppBundle:Hello:index ``. For more details
216
- on this controllers format, see :ref: `controller-string-syntax `.
216
+ on the controller format, see :ref: `controller-string-syntax `.
217
217
218
218
.. seealso ::
219
219
@@ -236,15 +236,12 @@ that is passed to that method::
236
236
// ...
237
237
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
238
238
239
- class HelloController
239
+ /**
240
+ * @Route("/hello/{name}", name="hello")
241
+ */
242
+ public function indexAction($name)
240
243
{
241
- /**
242
- * @Route("/hello/{name}", name="hello")
243
- */
244
- public function indexAction($name)
245
- {
246
- // ...
247
- }
244
+ // ...
248
245
}
249
246
250
247
The controller has a single argument, ``$name ``, which corresponds to the
@@ -260,6 +257,7 @@ Take the following more-interesting example:
260
257
261
258
// src/AppBundle/Controller/HelloController.php
262
259
// ...
260
+
263
261
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
264
262
265
263
class HelloController
@@ -360,7 +358,9 @@ the following guidelines in mind while you develop.
360
358
361
359
Every route also has a special ``_route `` parameter, which is equal to
362
360
the name of the route that was matched (e.g. ``hello ``). Though not usually
363
- useful, this is also available as a controller argument.
361
+ useful, this is also available as a controller argument. You can also
362
+ pass other variables from your route to your controller arguments. See
363
+ :doc: `/cookbook/routing/extra_information. `.
364
364
365
365
.. _book-controller-request-argument :
366
366
@@ -369,7 +369,7 @@ The ``Request`` as a Controller Argument
369
369
370
370
What if you need to read query parameters, grab a request header or get access
371
371
to an uploaded file? All of that information is stored in Symfony's ``Request ``
372
- object. To get it in your contorller , just add it as an argument and
372
+ object. To get it in your controller , just add it as an argument and
373
373
**type-hint it with the Request class **::
374
374
375
375
use Symfony\Component\HttpFoundation\Request;
@@ -384,7 +384,7 @@ object. To get it in your contorller, just add it as an argument and
384
384
.. seealso ::
385
385
386
386
Want to know more about getting information from the request? See
387
- :ref: `Access Request Information <component-http-foundation-request `.
387
+ :ref: `Access Request Information <component-http-foundation-request > `.
388
388
389
389
.. index ::
390
390
single: Controller; Base controller class
@@ -423,17 +423,6 @@ A great way to see the core functionality in action is to look in the
423
423
This is optional, but can give you more control over the exact objects/dependencies
424
424
that are injected into your controller.
425
425
426
- .. index ::
427
- single: Controller; Common tasks
428
-
429
- Common Controller Tasks
430
- -----------------------
431
-
432
- Yes, a controller can do anything. But most controllers do the same basic
433
- tasks over and over again. These tasks - like redirecting, rendering templates
434
- and accessing core services - are easier with the shortcut methods you get
435
- by extending the base ``Controller `` class.
436
-
437
426
.. index ::
438
427
single: Controller; Redirecting
439
428
@@ -502,19 +491,6 @@ The Symfony templating engine is explained in great detail in the
502
491
``AppBundle:Hello:index.html.twig `` would refer to the template located in
503
492
``src/AppBundle/Resources/views/Hello/index.html.twig ``. See :ref: `template-referencing-in-bundle `.
504
493
505
- .. tip ::
506
-
507
- The ``render `` method is a shortcut to direct use of the ``templating ``
508
- service. The ``templating `` service can also be used directly::
509
-
510
- $templating = $this->get('templating');
511
-
512
- // returns the content
513
- $content = $templating->render('Hello/index.html.twig', array('name' => $name));
514
-
515
- // puts the content into a Response object for convenience
516
- $content = $templating->renderResponse('Hello/index.html.twig', array('name' => $name));
517
-
518
494
.. index ::
519
495
single: Controller; Accessing services
520
496
@@ -526,7 +502,7 @@ Accessing other Services
526
502
Symfony comes packed with a lot of useful objects, called services. These
527
503
are used for rendering templates, sending emails, querying the database and
528
504
any other "work" you can think of. When you install a new bundle, it probably
529
- brings in even *more * services. And of course, will even :ref: ` add your own services < service-container-creating-service >`.
505
+ brings in even *more * services.
530
506
531
507
When extending the base controller class, you can access any Symfony service
532
508
via the ``get() `` method. Here are several common services you might need::
@@ -705,19 +681,19 @@ content that's sent back to the client::
705
681
$response->headers->set('Content-Type', 'application/json');
706
682
707
683
The ``headers `` property is a :class: `Symfony\\ Component\\ HttpFoundation\\ HeaderBag `
708
- object some nice methods for getting and setting the headers. The header
709
- names are normalized so that using ``Content-Type `` is equivalent to `` content-type ``
710
- or even ``content_type ``.
684
+ object and has some nice methods for getting and setting the headers. The
685
+ header names are normalized so that using ``Content-Type `` is equivalent to
686
+ `` content-type `` or even ``content_type ``.
711
687
712
688
There are also special classes to make certain kinds of responses easier:
713
689
714
- - For JSON, there is :class: `Symfony\\ Component\\ HttpFoundation\\ JsonResponse `.
690
+ * For JSON, there is :class: `Symfony\\ Component\\ HttpFoundation\\ JsonResponse `.
715
691
See :ref: `component-http-foundation-json-response `.
716
692
717
- - For files, there is :class: `Symfony\\ Component\\ HttpFoundation\\ BinaryFileResponse `.
693
+ * For files, there is :class: `Symfony\\ Component\\ HttpFoundation\\ BinaryFileResponse `.
718
694
See :ref: `component-http-foundation-serving-files `.
719
695
720
- - For streamed responses, there is :class: `Symfony\\ Component\\ HttpFoundation\\ StreamedResponse `.
696
+ * For streamed responses, there is :class: `Symfony\\ Component\\ HttpFoundation\\ StreamedResponse `.
721
697
See :ref: `streaming-response `.
722
698
723
699
.. seealso ::
@@ -763,7 +739,7 @@ Creating Static Pages
763
739
You can create a static page without even creating a controller (only a route
764
740
and template are needed).
765
741
766
- Use it! See :doc: `/cookbook/templating/render_without_controller `.
742
+ See :doc: `/cookbook/templating/render_without_controller `.
767
743
768
744
.. index ::
769
745
single: Controller; Forwarding
0 commit comments