-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
[quick tour] mostly typos #6275
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,13 +29,16 @@ When developing a Symfony application, your responsibility as a developer | |
is to write the code that maps the user's *request* (e.g. ``http://localhost:8000/``) | ||
to the *resource* associated with it (the ``Homepage`` HTML page). | ||
|
||
The code to execute is defined in **actions** and **controllers**. The mapping | ||
between user's requests and that code is defined via the **routing** configuration. | ||
And the contents displayed in the browser are usually rendered using **templates**. | ||
|
||
When you browsed ``http://localhost:8000/app/example`` earlier, Symfony executed | ||
the controller defined in the ``src/AppBundle/Controller/DefaultController.php`` | ||
file and rendered the ``app/Resources/views/default/index.html.twig`` template. | ||
The code to execute is defined as methods of PHP classes. The methods are | ||
called **actions** and the classes **controllers**, but in practice most | ||
developers use **controllers** to refer to both of them. The mapping between | ||
user's requests and that code is defined via the **routing** configuration. | ||
And the contents displayed in the browser are usually rendered using | ||
**templates**. | ||
|
||
When you go to ``http://localhost:8000/app/example``, Symfony will execut the | ||
controller in ``src/AppBundle/Controller/DefaultController.php`` and rendered | ||
the ``app/Resources/views/default/index.html.twig`` template. | ||
In the following sections you'll learn in detail the inner workings of Symfony | ||
controllers, routes and templates. | ||
|
||
|
@@ -69,7 +72,7 @@ is called ``Default`` and the PHP class is called ``DefaultController``. | |
The methods defined in a controller are called **actions**, they are usually | ||
associated with one URL of the application and their names are suffixed | ||
with ``Action``. In this example, the ``Default`` controller has only one | ||
action called ``index`` and defined in the ``indexAction`` method. | ||
action called ``index`` and defined in the ``indexAction()`` method. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so (to make things clear), +1 here :) |
||
|
||
Actions are usually very short - around 10-15 lines of code - because they | ||
just call other parts of the application to get or generate the needed | ||
|
@@ -85,7 +88,7 @@ Routing | |
Symfony routes each request to the action that handles it by matching the | ||
requested URL against the paths configured by the application. Open again | ||
the ``src/AppBundle/Controller/DefaultController.php`` file and take a look | ||
at the three lines of code above the ``indexAction`` method:: | ||
at the three lines of code above the ``indexAction()`` method:: | ||
|
||
// src/AppBundle/Controller/DefaultController.php | ||
namespace AppBundle\Controller; | ||
|
@@ -138,7 +141,8 @@ The only content of the ``index`` action is this PHP instruction:: | |
|
||
The ``$this->render()`` method is a convenient shortcut to render a template. | ||
Symfony provides some useful shortcuts to any controller extending from | ||
the ``Controller`` class. | ||
the base Symfony :class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller` | ||
class. | ||
|
||
By default, application templates are stored in the ``app/Resources/views/`` | ||
directory. Therefore, the ``default/index.html.twig`` template corresponds | ||
|
@@ -194,7 +198,7 @@ environments**. | |
What is an Environment? | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
An :term:`Environment` represents a group of configurations that's used | ||
An :term:`environment` represents a group of configurations that's used | ||
to run your application. Symfony defines two environments by default: ``dev`` | ||
(suited for when developing the application locally) and ``prod`` (optimized | ||
for when executing the application on production). | ||
|
@@ -235,7 +239,7 @@ In this example, the ``config_dev.yml`` configuration file imports the common | |
with its own options. | ||
|
||
For more details on environments, see | ||
":ref:`Environments & Front Controllers <page-creation-environments>`" article. | ||
":ref:`page-creation-environments`" section of the book. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
Final Thoughts | ||
-------------- | ||
|
@@ -246,6 +250,4 @@ how Symfony makes it really easy to implement web sites better and faster. | |
If you are eager to learn more about Symfony, dive into the next section: | ||
":doc:`The View <the_view>`". | ||
|
||
.. _Composer: https://getcomposer.org/ | ||
.. _executable installer: https://getcomposer.org/download | ||
.. _Twig: http://twig.sensiolabs.org/ | ||
.. _`Twig`: http://twig.sensiolabs.org/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ about this template engine. This section just gives you a quick overview | |
of its main concepts. | ||
|
||
A Twig template is a text file that can generate any type of content (HTML, | ||
CSS, JavaScript, XML, CSV, LaTeX, etc.) Twig elements are separated from | ||
CSS, JavaScript, XML, CSV, LaTeX, etc.). Twig elements are separated from | ||
the rest of the template contents using any of these delimiters: | ||
|
||
``{{ ... }}`` | ||
|
@@ -50,7 +50,7 @@ Below is a minimal template that illustrates a few basics, using two variables | |
</body> | ||
</html> | ||
|
||
To render a template in Symfony, use the ``render`` method from within a | ||
To render a template in Symfony, use the ``render()`` method from within a | ||
controller. If the template needs variables to generate its contents, pass | ||
them as an array using the second optional argument:: | ||
|
||
|
@@ -160,7 +160,7 @@ Don't forget to check out the official `Twig documentation`_ to learn everything | |
about filters, functions and tags. | ||
|
||
Including other Templates | ||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
------------------------- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I propose this change because I don't see why the content under title "Including other Templates" (and "Embedding other Controllers") would be subtitle of the title "Using Tags, Filters and Functions" based on the content. If this decision is based on the fact that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with this change - I can see both sides |
||
|
||
The best way to share a snippet of code between several templates is to | ||
create a new template fragment that can then be included from other templates. | ||
|
@@ -190,7 +190,7 @@ using the ``include()`` function: | |
{% endblock %} | ||
|
||
Embedding other Controllers | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
--------------------------- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
|
||
And what if you want to embed the result of another controller in a template? | ||
That's very useful when working with Ajax, or when the embedded template | ||
|
@@ -212,7 +212,6 @@ action of the ``Default`` controller (the ``AppBundle`` part will be explained | |
later):: | ||
|
||
// src/AppBundle/Controller/DefaultController.php | ||
|
||
class DefaultController extends Controller | ||
{ | ||
public function topArticlesAction() | ||
|
@@ -229,31 +228,31 @@ later):: | |
} | ||
|
||
Creating Links between Pages | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
---------------------------- | ||
|
||
Creating links between pages is a must for web applications. Instead of | ||
hardcoding URLs in templates, the ``path`` function knows how to generate | ||
URLs based on the routing configuration. That way, all your URLs can be | ||
easily updated by just changing the configuration: | ||
hardcoding URLs in templates, the ``path()`` function knows how to generate | ||
URLs based on the routing configuration. That way, all your URLs | ||
can be easily updated by just changing the configuration: | ||
|
||
.. code-block:: html+twig | ||
|
||
<a href="{{ path('homepage') }}">Return to homepage</a> | ||
|
||
The ``path`` function takes the route name as the first argument and you | ||
The ``path()`` function takes the route name as the first argument and you | ||
can optionally pass an array of route parameters as the second argument. | ||
|
||
.. tip:: | ||
|
||
The ``url`` function is very similar to the ``path`` function, but generates | ||
The ``url()`` function is very similar to the ``path()`` function, but generates | ||
*absolute* URLs, which is very handy when rendering emails and RSS files: | ||
``<a href="{{ url('homepage') }}">Visit our website</a>``. | ||
|
||
Including Assets: Images, JavaScripts and Stylesheets | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
----------------------------------------------------- | ||
|
||
What would the Internet be without images, JavaScripts and stylesheets? | ||
Symfony provides the ``asset`` function to deal with them easily: | ||
Symfony provides the ``asset()`` function to deal with them easily: | ||
|
||
.. code-block:: twig | ||
|
||
|
@@ -262,10 +261,11 @@ Symfony provides the ``asset`` function to deal with them easily: | |
<img src="{{ asset('images/logo.png') }}" /> | ||
|
||
The ``asset()`` function looks for the web assets inside the ``web/`` directory. | ||
If you store them in another directory, read :doc:`this article </cookbook/assetic/asset_management>` | ||
If you store them in another directory, read | ||
:doc:`this article </cookbook/assetic/asset_management>` | ||
to learn how to manage web assets. | ||
|
||
Using the ``asset`` function, your application is more portable. The reason | ||
Using the ``asset()`` function, your application is more portable. The reason | ||
is that you can move the application root directory anywhere under your | ||
web root directory without changing anything in your template's code. | ||
|
||
|
@@ -285,5 +285,5 @@ But I'm getting ahead of myself. First, you need to learn more about the | |
controller and that's exactly the topic of the :doc:`next part of this tutorial | ||
<the_controller>`. Ready for another 10 minutes with Symfony? | ||
|
||
.. _Twig: http://twig.sensiolabs.org/ | ||
.. _Twig documentation: http://twig.sensiolabs.org/documentation | ||
.. _`Twig`: http://twig.sensiolabs.org/ | ||
.. _`Twig documentation`: http://twig.sensiolabs.org/documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is technically not wrong ... but I prefer this syntax too :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposed changed is more common throughout the documentation.