diff --git a/quick_tour/the_architecture.rst b/quick_tour/the_architecture.rst index c878ce08c5c..fe8be5a240b 100644 --- a/quick_tour/the_architecture.rst +++ b/quick_tour/the_architecture.rst @@ -257,7 +257,7 @@ Understanding the Cache and Logs -------------------------------- Symfony applications can contain several configuration files defined in -several formats (YAML, XML, PHP, etc.) Instead of parsing and combining +several formats (YAML, XML, PHP, etc.). Instead of parsing and combining all those files for each request, Symfony uses its own cache system. In fact, the application configuration is only parsed for the very first request and then compiled down to plain PHP code stored in the ``app/cache/`` @@ -309,4 +309,4 @@ need to learn a lot to become a Symfony master. Ready to dig into these topics now? Look no further - go to the official :doc:`/book/index` and pick any topic you want. -.. _Composer: https://getcomposer.org +.. _`Composer`: https://getcomposer.org diff --git a/quick_tour/the_big_picture.rst b/quick_tour/the_big_picture.rst index af5edbeab18..680520dad3e 100644 --- a/quick_tour/the_big_picture.rst +++ b/quick_tour/the_big_picture.rst @@ -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. 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 `" article. +":ref:`page-creation-environments`" section of the book. 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 `". -.. _Composer: https://getcomposer.org/ -.. _executable installer: https://getcomposer.org/download -.. _Twig: http://twig.sensiolabs.org/ +.. _`Twig`: http://twig.sensiolabs.org/ diff --git a/quick_tour/the_controller.rst b/quick_tour/the_controller.rst index 07f30142699..b7dc01b672e 100644 --- a/quick_tour/the_controller.rst +++ b/quick_tour/the_controller.rst @@ -15,8 +15,9 @@ result of executing any action of any controller is the creation of a to the user. So far, all the actions shown in this tutorial used the ``$this->render()`` -shortcut to return a rendered response as result. In case you need it, you -can also create a raw ``Response`` object to return any text content:: +controller shortcut method to return a rendered template as result. In case +you need it, you can also create a raw ``Response`` object to return any +text content:: // src/AppBundle/Controller/DefaultController.php namespace AppBundle\Controller; @@ -51,7 +52,7 @@ each value. Let's create a new action with route variables to show this feature in action. Open the ``src/AppBundle/Controller/DefaultController.php`` file and add -a new method called ``helloAction`` with the following content:: +a new method called ``helloAction()`` with the following content:: // src/AppBundle/Controller/DefaultController.php namespace AppBundle\Controller; @@ -343,4 +344,4 @@ That's all there is to it and I'm not even sure you'll have spent the full 10 minutes. You were briefly introduced to bundles in the first part and all the features you've learned about so far are part of the core FrameworkBundle. But thanks to bundles, everything in Symfony can be extended or replaced. -That's the topic of the :doc:`next part of this tutorial `. +That's the topic of the :doc:`next part of this tutorial `. \ No newline at end of file diff --git a/quick_tour/the_view.rst b/quick_tour/the_view.rst index 7609730f916..e419be70ade 100644 --- a/quick_tour/the_view.rst +++ b/quick_tour/the_view.rst @@ -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 -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 -~~~~~~~~~~~~~~~~~~~~~~~~~ +------------------------- 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 -~~~~~~~~~~~~~~~~~~~~~~~~~~~ +--------------------------- 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 Return to homepage -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: ``Visit our website``. 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: The ``asset()`` function looks for the web assets inside the ``web/`` directory. -If you store them in another directory, read :doc:`this article ` +If you store them in another directory, read +:doc:`this article ` 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 `. 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