@@ -75,11 +75,16 @@ environment:
75
75
If you see a lucky number being printed back to you, congratulations! But before
76
76
you run off to play the lottery, check out how this works.
77
77
78
- The ``@Route `` above ``numberAction() `` method is called an *annotation * and it
78
+ The ``@Route `` above ``numberAction() `` is called an *annotation * and it
79
79
defines the URL pattern. You can also write routes in YAML (or other formats):
80
80
read about this in the :doc: `routing </book/routing >` chapter. Actually, most
81
81
routing examples in the docs have tabs that show you how each format looks.
82
82
83
+ The method below the annotation - ``numberAction `` - is called the *controller *
84
+ and is where you build the page. The only rule is that a controller *must *
85
+ return a Symfony :ref: `Response <component-http-foundation-response >` object
86
+ (and you'll even learn to bend this rule eventually).
87
+
83
88
Creating a JSON Response
84
89
~~~~~~~~~~~~~~~~~~~~~~~~
85
90
@@ -150,8 +155,8 @@ Dynamic URL Patterns: /lucky/number/{count}
150
155
151
156
Woh, you're doing great! But Symfony's routing can do a lot more. Suppose
152
157
now that you want a user to be able to go to ``/lucky/number/5 `` to generate
153
- *5 * lucky numbers at once. Update the route to have a " wildcard" placeholders
154
- `` {counter} `` at the end: :
158
+ *5 * lucky numbers at once. Update the route to have a `` { wildcard} `` part
159
+ at the end:
155
160
156
161
.. configuration-block ::
157
162
@@ -207,7 +212,7 @@ now that you want a user to be able to go to ``/lucky/number/5`` to generate
207
212
208
213
return $collection;
209
214
210
- Because of the ``{count} `` "wildcard" placeholders , the URL to the page is *different *:
215
+ Because of the ``{count} `` "wildcard" placeholder , the URL to the page is *different *:
211
216
it now works for URLs matching ``/lucky/number/* `` - for example ``/lucky/number/5 ``.
212
217
The best part is that you can access this value and use it in your controller::
213
218
@@ -241,8 +246,8 @@ Try it by printing *7* lucky numbers:
241
246
http://localhost:8000/lucky/number/7
242
247
243
248
**You can get the value of any ``{placeholder}`` in your route by adding
244
- a ``$placeholder`` argument to your controller. Just make sure they have
245
- the same name. **
249
+ a ``$placeholder`` argument to your controller. Just make sure that the placeholder
250
+ (e.g. ``{id}``) matches the argument name (e.g. ``$id``) . **
246
251
247
252
The routing system can do a *lot * more, like supporting multiple placeholders
248
253
(e.g. ``/blog/{category}/{page}) ``), making placeholders optional and forcing
@@ -356,7 +361,7 @@ If you refresh your browser now, you'll get an error:
356
361
Unable to find template "lucky/number.html.twig"
357
362
358
363
Fix that by creating a new ``app/Resources/views/lucky `` directory and putting
359
- a ``number.html.twig `` file inside of it::
364
+ a ``number.html.twig `` file inside of it:
360
365
361
366
.. configuration-block ::
362
367
@@ -380,14 +385,13 @@ a ``number.html.twig`` file inside of it::
380
385
381
386
Welcome to Twig! This simple file already shows off the basics:
382
387
383
- * ``{{ variableName }} `` syntax is used to print a variable that you're
384
- passing into the template from the array list in `` render() `` method in your
385
- controller.
388
+ * The ``{{ variableName }} `` syntax is used to print something. In this template,
389
+ `` luckyNumberList `` is a variable that you're passing into the template from the
390
+ `` render `` call in the controller.
386
391
387
392
* The ``{% extends 'base.html.twig' %} `` points to a layout file that lives
388
- at `app/Resources/views/base.html.twig `_ and came with your new project
389
- Symfony Standard Edition. It's *really * basic (an unstyled HTML structure)
390
- and it's yours to customize.
393
+ at `app/Resources/views/base.html.twig `_ and came with your new project. It's
394
+ *really * basic (an unstyled HTML structure) and it's yours to customize.
391
395
392
396
* The ``{% block body %} `` part uses Twig's :ref: `inheritance system <twig-inheritance >`
393
397
to put the content into the middle of the ``base.html.twig `` layout.
@@ -441,8 +445,8 @@ the :doc:`Bundles </book/bundles>` chapter.
441
445
So what about the other directories in the project?
442
446
443
447
``vendor/ ``
444
- Location to which vendor (i.e. third-party ) libraries and bundles are
445
- downloaded by the `Composer `_ package manager.
448
+ Third-party (i.e. "vendor" ) libraries live here! These are typically downloaded
449
+ via the `Composer `_ package manager.
446
450
447
451
``web/ ``
448
452
This is the document root for the project and contains any publicly accessible
@@ -452,15 +456,14 @@ So what about the other directories in the project?
452
456
.. seealso ::
453
457
454
458
Symfony is flexible. If you need to, you can easily override the default
455
- directory structure. See cookbook article
456
- :doc: `/cookbook/configuration/override_dir_structure `.
459
+ directory structure. See :doc: `/cookbook/configuration/override_dir_structure `.
457
460
458
461
Application Configuration
459
462
-------------------------
460
463
461
- Symfony Standard Edition comes with several built-in bundles (open your
462
- `` app/AppKernel.php `` file) and you'll probably install more. The main configuration
463
- file for bundles is ``app/config/config.yml ``: :
464
+ Symfony comes with several built-in bundles (open your `` app/AppKernel.php ``
465
+ file) and you'll probably install more. The main configuration file for bundles
466
+ is ``app/config/config.yml ``:
464
467
465
468
.. configuration-block ::
466
469
@@ -530,8 +533,8 @@ file for bundles is ``app/config/config.yml``::
530
533
531
534
// ...
532
535
533
- The ``framework `` key configures `` FrameworkBundle `` , the ``twig `` key configures
534
- `` TwigBundle `` and so on. A *lot * of behavior in Symfony can be controlled just
536
+ The ``framework `` key configures FrameworkBundle, the ``twig `` key configures
537
+ TwigBundle and so on. A *lot * of behavior in Symfony can be controlled just
535
538
by changing one option in this configuration file. To find out how, see the
536
539
:doc: `Configuration Reference </reference/index >` section.
537
540
0 commit comments