Skip to content

Added php start tag to page_creation.rst #5741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions book/page_creation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Suppose you want to create a page - ``/lucky/number`` - that generates a
lucky (well, random) number and prints it. To do that, create a class and
a method inside of it that will be executed when someone goes to ``/lucky/number``::

<?php
// src/AppBundle/Controller/LuckyController.php
namespace AppBundle\Controller;

Expand Down Expand Up @@ -101,6 +102,7 @@ or the status code.
Suppose you want to create a JSON endpoint that returns the lucky number.
Just add a second method to ``LuckyController``::

<?php
// src/AppBundle/Controller/LuckyController.php
// ...

Expand Down Expand Up @@ -131,6 +133,7 @@ Try this out in your browser:

You can even shorten this with the handy :class:`Symfony\\Component\\HttpFoundation\\JsonResponse`::

<?php
// src/AppBundle/Controller/LuckyController.php
// ...

Expand Down Expand Up @@ -167,6 +170,7 @@ at the end:

.. code-block:: php-annotations

<?php
// src/AppBundle/Controller/LuckyController.php
// ...

Expand Down Expand Up @@ -221,6 +225,7 @@ Because of the ``{count}`` "placeholder", the URL to the page is *different*:
it now works for URLs matching ``/lucky/number/*`` - for example ``/lucky/number/5``.
The best part is that you can access this value and use it in your controller::

<?php
// src/AppBundle/Controller/LuckyController.php
// ...

Expand Down Expand Up @@ -273,6 +278,7 @@ So far, ``LuckyController`` doesn't extend any base class. The easiest way
to use Twig - or many other tools in Symfony - is to extend Symfony's base
:class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller` class::

<?php
// src/AppBundle/Controller/LuckyController.php
// ...

Expand All @@ -295,6 +301,7 @@ Twig templates, another that can log messages and many more.

To render a Twig template, use a service called ``templating``::

<?php
// src/AppBundle/Controller/LuckyController.php
// ...

Expand Down Expand Up @@ -328,6 +335,7 @@ and this has a ``render()`` method.
But this can get even easier! By extending the ``Controller`` class, you
also get a lot of shortcut methods, like ``render()``::

<?php
// src/AppBundle/Controller/LuckyController.php
// ...

Expand Down