Skip to content

Page Creation Small Changes #10177

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 5 commits 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
52 changes: 19 additions & 33 deletions page_creation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ to creating a page?
return a ``Response`` object. You'll learn more about :doc:`controllers </controller>`
in their own section, including how to return JSON responses.

.. tip::

To create controllers faster, let Symfony generate it for you:

.. code-block:: terminal

$ php bin/console make:controller

.. _annotation-routes:

Annotation Routes
Expand Down Expand Up @@ -126,14 +134,6 @@ You can now add your route directly *above* the controller:
That's it! The page - ``http://localhost:8000/lucky/number`` will work exactly
like before! Annotations are the recommended way to configure routes.

.. tip::

To create controllers faster, let Symfony generate it for you:

.. code-block:: terminal

$ php bin/console make:controller

.. _flex-quick-intro:

Auto-Installing Recipes with Symfony Flex
Expand Down Expand Up @@ -176,36 +176,28 @@ To get a list of *all* of the routes in your system, use the ``debug:router`` co

$ php bin/console debug:router

You should see your *one* route so far:
You should see your `app_lucky_number` route at the very top:

================== ======== ======== ====== ===============
Name Method Scheme Host Path
================== ======== ======== ====== ===============
app_lucky_number ANY ANY ANY /lucky/number
================== ======== ======== ====== ===============

You will also see debugging routes below `app_lucky_number` -- more on the debugging routes in the next section.

You'll learn about many more commands as you continue!

The Web Debug Toolbar: Debugging Dream
--------------------------------------

One of Symfony's *killer* features is the Web Debug Toolbar: a bar that displays
a *huge* amount of debugging information along the bottom of your page while developing.

To use the web debug toolbar, install the Profiler pack first:

.. code-block:: terminal
a *huge* amount of debugging information along the bottom of your page while developing. This is all
included out of the box using a package called ``symfony/profiler-pack``.

$ composer require --dev symfony/profiler-pack

As soon as this finishes, refresh your page. You should see a black bar along the
bottom of the page. You'll learn more about all the information it holds along the
way, but feel free to experiment: hover over and click the different icons to get
information about routing, performance, logging and more.

This is also a great example of Flex! After downloading the profiler package,
the recipe created several configuration files so that the web debug toolbar
worked instantly.
You will see a black bar along the bottom of the page. You'll learn more about all the information it holds
along the way, but feel free to experiment: hover over and click
the different icons to get information about routing, performance, logging and more.

Rendering a Template
--------------------
Expand All @@ -214,13 +206,7 @@ If you're returning HTML from your controller, you'll probably want to render
a template. Fortunately, Symfony comes with `Twig`_: a templating language that's
easy, powerful and actually quite fun.

First, install Twig:

.. code-block:: terminal

$ composer require symfony/twig-bundle

Second, make sure that ``LuckyController`` extends Symfony's base
Make sure that ``LuckyController`` extends Symfony's base
:class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController` class:

.. code-block:: diff
Expand Down Expand Up @@ -251,9 +237,9 @@ variable so you can use it in Twig::
{
$number = random_int(0, 100);

return $this->render('lucky/number.html.twig', array(
return $this->render('lucky/number.html.twig', [
'number' => $number,
));
]);
}
}

Expand Down