@@ -102,7 +102,7 @@ the code that prepares the HTML "presentation"::
102102 require 'templates/list.php';
103103
104104
105- The HTML code is now stored in a separate ``templates/list.php `` file , which
105+ The HTML code is now stored in a separate file ``templates/list.php ``, which
106106is primarily an HTML file that uses a template-like PHP syntax:
107107
108108.. code-block :: html+php
@@ -338,9 +338,8 @@ application change slightly, but start to become more flexible:
338338
339339 .. tip ::
340340
341- Using Apache's ``mod_rewrite `` (or equivalent with other web servers),
342- the URL can easily be cleaned up - ``index.php `` portion removed -
343- to be just ``/show ``.
341+ By using rewrite rules in your :doc: `web server configuration </cookbook/configuration/web_server_configuration >`,
342+ the ``index.php `` won't be needed and you will have beautiful, clean URLs (e.g. ``/show ``).
344343
345344When using a front controller, a single PHP file (``index.php `` in this case)
346345renders *every * request. For the blog post show page, ``/index.php/show `` will
@@ -375,10 +374,7 @@ on the requested URI::
375374 }
376375
377376For organization, both controllers (formerly ``index.php `` and ``show.php ``)
378- are now PHP functions and each has been moved into a separate file named
379- ``controllers.php ``. The job of each PHP function, now called a
380- :term: `controller `, is to use information from the ``Request `` object to create
381- and return a ``Response `` object::
377+ are now PHP functions and each has been moved into a separate file named ``controllers.php ``::
382378
383379 // controllers.php
384380 function list_action()
@@ -397,15 +393,11 @@ As a front controller, ``index.php`` has taken on an entirely new role, one
397393that includes loading the core libraries and routing the application so that
398394one of the two controllers (the ``list_action() `` and ``show_action() ``
399395functions) is called. In reality, the front controller is beginning to look and
400- act a lot like Symfony's mechanism for handling and routing requests.
396+ act a lot like how Symfony handles and routes requests.
401397
402- .. note ::
403-
404- Though similarly named, a "front controller" is different from the PHP functions
405- called "controllers" talked about in this chapter. A front controller is a short PHP
406- file through which all requests are directed. "Controller" functions are grouped in
407- several files and they hold your code which creates and returns the appropriate
408- ``Response `` object. Controllers are also called *actions *.
398+ But but careful not to confuse the terms *front controller * and *controller *. Your
399+ app will usually have just *one * front controller, which boots your code. You will
400+ have *many * controller functions: one for each page.
409401
410402.. tip ::
411403
@@ -458,7 +450,7 @@ into a ``vendor/`` directory:
458450
459451 Beside downloading your dependencies, Composer generates a ``vendor/autoload.php `` file,
460452which takes care of autoloading for all the files in the Symfony Framework as well as
461- the files mentioned in the `` autoload `` section of your ``composer.json ``.
453+ the files mentioned in the autoload section of your ``composer.json ``.
462454
463455Core to Symfony's philosophy is the idea that an application's main job is
464456to interpret each request and return a response. To this end, Symfony provides
@@ -535,6 +527,8 @@ allowing HTTP headers and content to be added via an object-oriented interface.
535527And while the responses in this application are simple, this flexibility
536528will pay dividends as your application grows.
537529
530+ .. _the-sample-application-in-symfony2 :
531+
538532The Sample Application in Symfony
539533~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
540534
@@ -583,12 +577,11 @@ them for you. Here's the same sample application, now built in Symfony::
583577 }
584578 }
585579
586- First we have a "controller class" which is a convenient way to group several
587- "controllers" together. So methods inside a controller class are controllers
588- also called *actions *. They hold code which creates and returns the appropriate
589- ``Response `` object.
580+ Notice, both controller functions now live inside a "controller class". This is a
581+ nice way to group related pages. The controller functions are also sometimes called
582+ *actions *.
590583
591- The two controllers are still lightweight. Each uses the
584+ The two controllers (or actions) are still lightweight. Each uses the
592585:doc: `Doctrine ORM library </book/doctrine >` to retrieve objects from the
593586database and the Templating component to render a template and return a
594587``Response `` object. The list ``list.php `` template is now quite a bit simpler:
@@ -634,12 +627,12 @@ The layout ``layout.php`` is nearly identical:
634627
635628.. note ::
636629
637- The show ``show.php `` template is left as an exercise, as it should be trivial to
638- create based on the list ``list.php `` template.
630+ The show ``show.php `` template is left as an exercise: updating it should be
631+ really similar to updating the ``list.php `` template.
639632
640633When Symfony's engine (called the :term: `Kernel `) boots up, it needs a map so
641634that it knows which controllers to execute based on the request information.
642- A routing configuration map ``app/config/routing.yml `` provides this information
635+ A routing configuration map - ``app/config/routing.yml `` - provides this information
643636in a readable format:
644637
645638.. code-block :: yaml
@@ -655,8 +648,7 @@ in a readable format:
655648
656649 Now that Symfony is handling all the mundane tasks, the front controller
657650``web/app.php `` is dead simple. And since it does so little, you'll never
658- have to touch it once it's created (and if you use a `Symfony distribution `_,
659- you won't even need to create it!)::
651+ have to touch it::
660652
661653 // web/app.php
662654 require_once __DIR__.'/../app/bootstrap.php';
@@ -667,21 +659,23 @@ you won't even need to create it!)::
667659 $kernel = new AppKernel('prod', false);
668660 $kernel->handle(Request::createFromGlobals())->send();
669661
670- Front controller's only job is to initialize Symfony's engine (called the
662+ The front controller's only job is to initialize Symfony's engine (called the
671663:term: `Kernel `) and pass it a ``Request `` object to handle. The Symfony core
672664asks the router to inspect the request. The router matches the incoming URL
673665to a specific route and returns information about the route, including the
674666controller that should be executed. The correct controller from the matched
675- route is executed and the code inside the controller creates and returns the
667+ route is executed and your code inside the controller creates and returns the
676668appropriate ``Response `` object. The HTTP headers and content of the ``Response ``
677669object are sent back to the client.
678670
671+ It's a beautiful thing.
672+
679673.. figure :: /images/request-flow.png
680674 :align: center
681675 :alt: Symfony request flow
682676
683- PHP Templates versus Twig Templates
684- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
677+ Better Templates
678+ ~~~~~~~~~~~~~~~~
685679
686680If you choose to use it, Symfony comes standard with a templating engine
687681called `Twig `_ that makes templates faster to write and easier to read.
@@ -726,15 +720,14 @@ And rewriting ``layout.html.php`` template in Twig would look like this:
726720
727721Twig is well-supported in Symfony. And while PHP templates will always
728722be supported in Symfony, the many advantages of Twig will continue to
729- be discussed. For more information, see the :doc: `Templating chapter </book/templating >`.
730-
723+ be discussed. For more information, see the :doc: `templating chapter </book/templating >`.
731724
732725Where Symfony Delivers
733726----------------------
734727
735728In the upcoming chapters, you'll learn more about how each piece of Symfony
736- works and the recommended organization of a project. For now, have a look
737- at how migrating the blog from flat PHP to Symfony has improved life:
729+ works and how you can organize your project. For now, celebrate at how migrating
730+ the blog from flat PHP to Symfony has improved life:
738731
739732* Your application now has **clear and consistently organized code ** (though
740733 Symfony doesn't force you into this). This promotes **reusability ** and
@@ -769,14 +762,12 @@ Learn more from the Cookbook
769762* :doc: `/cookbook/templating/PHP `
770763* :doc: `/cookbook/controller/service `
771764
772-
773765.. _`Model-View-Controller` : https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller
774766.. _`Doctrine` : http://www.doctrine-project.org
775767.. _`SQL injection attack` : https://en.wikipedia.org/wiki/SQL_injection
776768.. _`Composer` : https://getcomposer.org
777769.. _`download Composer` : https://getcomposer.org/download/
778- .. _`Symfony distribution` : https://github.com/symfony/symfony-standard
779- .. _`Twig` : http://twig.sensiolabs.org
780770.. _`Validator` : https://github.com/symfony/validator
781771.. _`Varnish` : https://www.varnish-cache.org/
782- .. _`KnpBundles.com` : http://knpbundles.com/
772+ .. _`KnpBundles.com` : http://knpbundles.com/
773+ .. _`Twig` : http://twig.sensiolabs.org
0 commit comments