diff --git a/book/controller.rst b/book/controller.rst index 6089eb7bdd9..192d7d15a2e 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -73,7 +73,7 @@ maps a URL to that controller (#2). .. note:: Though similarly named, a "front controller" is different from the - "controllers" we'll talk about in this chapter. A front controller + "controllers" talked about in this chapter. A front controller is a short PHP file that lives in your web directory and through which all requests are directed. A typical application will have a production front controller (e.g. ``app.php``) and a development front controller @@ -324,7 +324,7 @@ working with forms, for example:: public function updateAction(Request $request) { $form = $this->createForm(...); - + $form->bindRequest($request); // ... } @@ -441,7 +441,7 @@ object that's returned from that controller:: )); // ... further modify the response or return it directly - + return $response; } @@ -470,7 +470,7 @@ value to each variable. a shortcut for core Symfony2 functionality. A forward can be accomplished directly via the ``http_kernel`` service. A forward returns a ``Response`` object:: - + $httpKernel = $this->container->get('http_kernel'); $response = $httpKernel->forward('AcmeHelloBundle:Hello:fancy', array( 'name' => $name, @@ -509,7 +509,7 @@ The Symfony templating engine is explained in great detail in the The ``renderView`` method is a shortcut to direct use of the ``templating`` service. The ``templating`` service can also be used directly:: - + $templating = $this->get('templating'); $content = $templating->render('AcmeHelloBundle:Hello:index.html.twig', array('name' => $name)); @@ -662,7 +662,7 @@ the ``notice`` message: {% endif %} .. code-block:: php - + hasFlash('notice')): ?>
getFlash('notice') ?> @@ -686,7 +686,7 @@ headers and content that's sent back to the client:: // create a simple Response with a 200 status code (the default) $response = new Response('Hello '.$name, 200); - + // create a JSON-response with a 200 status code $response = new Response(json_encode(array('name' => $name))); $response->headers->set('Content-Type', 'application/json'); diff --git a/book/from_flat_php_to_symfony2.rst b/book/from_flat_php_to_symfony2.rst index b825a29848b..c0448af1f0d 100644 --- a/book/from_flat_php_to_symfony2.rst +++ b/book/from_flat_php_to_symfony2.rst @@ -11,7 +11,7 @@ better software than with flat PHP, you'll see for yourself. In this chapter, you'll write a simple application in flat PHP, and then refactor it to be more organized. You'll travel through time, seeing the decisions behind why web development has evolved over the past several years -to where it is now. +to where it is now. By the end, you'll see how Symfony2 can rescue you from mundane tasks and let you take back control of your code. @@ -134,7 +134,7 @@ to the area of *your* code that processes user input and prepares the response. In this case, our controller prepares data from the database and then includes a template to present that data. With the controller isolated, you could easily change *just* the template file if you needed to render the blog -entries in some other format (e.g. ``list.json.php`` for JSON format). +entries in some other format (e.g. ``list.json.php`` for JSON format). Isolating the Application (Domain) Logic ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -532,7 +532,7 @@ The Sample Application in Symfony2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The blog has come a *long* way, but it still contains a lot of code for such -a simple application. Along the way, we've also invented a simple routing +a simple application. Along the way, you've made a simple routing system and a method using ``ob_start()`` and ``ob_get_clean()`` to render templates. If, for some reason, you needed to continue building this "framework" from scratch, you could at least use Symfony's standalone `Routing`_ and @@ -564,7 +564,7 @@ them for you. Here's the same sample application, now built in Symfony2:: ->getRepository('AcmeBlogBundle:Post') ->find($id) ; - + if (!$post) { // cause the 404 page not found to be displayed throw $this->createNotFoundException(); @@ -581,7 +581,7 @@ now quite a bit simpler: .. code-block:: html+php - + extend('::layout.html.php') ?> set('title', 'List of Posts') ?> @@ -614,7 +614,7 @@ The layout is nearly identical: .. note:: - We'll leave the show template as an exercise, as it should be trivial to + The show template is left as an exercise, as it should be trivial to create based on the list template. When Symfony2's engine (called the ``Kernel``) boots up, it needs a map so @@ -730,8 +730,8 @@ The corresponding ``layout.html.twig`` template is also easier to write: Twig is well-supported in Symfony2. And while PHP templates will always -be supported in Symfony2, we'll continue to discuss the many advantages of -Twig. For more information, see the :doc:`templating chapter`. +be supported in Symfony2, the many advantages of Twig will continue to +be discussed. For more information, see the :doc:`templating chapter`. Learn more from the Cookbook ---------------------------- diff --git a/book/page_creation.rst b/book/page_creation.rst index 73e4a0e03b0..1a6c303e222 100644 --- a/book/page_creation.rst +++ b/book/page_creation.rst @@ -255,10 +255,10 @@ application should greet you: .. code-block:: text http://localhost/app.php/hello/Ryan - + If you get an error, it's likely because you need to clear your cache by running: - + .. code-block:: bash $ php app/console cache:clear --env=prod --no-debug @@ -299,8 +299,8 @@ of writing the HTML inside the controller, render a template instead: .. note:: - In order to use the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::render` - method, your controller must extend the + In order to use the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::render` + method, your controller must extend the :class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller` class, which adds shortcuts for tasks that are common inside controllers. This is done in the above example by adding the ``use`` statement on line 4 @@ -476,7 +476,7 @@ use a Kernel class, ``AppKernel``, to bootstrap the application. http://localhost/hello/Ryan Though front controllers are essential in handling every request, you'll -rarely need to modify or even think about them. We'll mention them again +rarely need to modify or even think about them. They'll be mentioned again briefly in the `Environments`_ section. The Application (``app``) Directory @@ -731,7 +731,7 @@ format you prefer: imports: - { resource: parameters.ini } - { resource: security.yml } - + framework: secret: "%secret%" charset: UTF-8 @@ -758,7 +758,7 @@ format you prefer: - + diff --git a/book/security.rst b/book/security.rst index b2e34b17420..14da7adfd4b 100644 --- a/book/security.rst +++ b/book/security.rst @@ -874,7 +874,7 @@ Users ----- In the previous sections, you learned how you can protect different resources -by requiring a set of *roles* for a resource. In this section we'll explore +by requiring a set of *roles* for a resource. This section explores the other side of authorization: users. Where do Users come from? (*User Providers*) @@ -1199,7 +1199,7 @@ look like:: method of an anonymous user object will return true. To check if your user is actually authenticated, check for the ``IS_AUTHENTICATED_FULLY`` role. - + In a Twig Template this object can be accessed via the ``app.user`` key, which calls the :method:`GlobalVariables::getUser()` method: @@ -1570,7 +1570,7 @@ Access Control in Controllers ----------------------------- If you want to check if the current user has a role in your controller, use -the :method:`Symfony\\Component\\Security\\Core\\SecurityContext::isGranted` +the :method:`Symfony\\Component\\Security\\Core\\SecurityContext::isGranted` method of the security context:: public function indexAction() diff --git a/book/templating.rst b/book/templating.rst index 141ebd1cc3d..534cb7e4f10 100644 --- a/book/templating.rst +++ b/book/templating.rst @@ -175,8 +175,8 @@ Template Inheritance and Layouts -------------------------------- More often than not, templates in a project share common elements, like the -header, footer, sidebar or more. In Symfony2, we like to think about this -problem differently: a template can be decorated by another one. This works +header, footer, sidebar or more. In Symfony2, this problem is thought about +differently: a template can be decorated by another one. This works exactly the same as PHP classes: template inheritance allows you to build a base "layout" template that contains all the common elements of your site defined as **blocks** (think "PHP class with base methods"). A child template @@ -468,8 +468,8 @@ ease the work of the template designer. In PHP, the templating system provides an extensible *helper* system that provides useful features in a template context. -We've already seen a few built-in Twig tags (``{% block %}`` & ``{% extends %}``) -as well as an example of a PHP helper (``$view['slots']``). Let's learn a +You've already seen a few built-in Twig tags (``{% block %}`` & ``{% extends %}``) +as well as an example of a PHP helper (``$view['slots']``). Here you will learn a few more. .. index:: @@ -551,7 +551,7 @@ template using the ``with`` command. .. tip:: The ``{'article': article}`` syntax is the standard Twig syntax for hash - maps (i.e. an array with named keys). If we needed to pass in multiple + maps (i.e. an array with named keys). If you needed to pass in multiple elements, it would look like this: ``{'foo': foo, 'bar': bar}``. .. index:: @@ -607,7 +607,7 @@ The ``recentList`` template is perfectly straightforward: .. note:: - Notice that we've cheated and hardcoded the article URL in this example + Notice that the article URL is hardcoded in this example (e.g. ``/article/*slug*``). This is a bad practice. In the next section, you'll learn how to do this correctly. @@ -810,7 +810,7 @@ advantage of Symfony's template inheritance. This section will teach you the philosophy behind including stylesheet and Javascript assets in Symfony. Symfony also packages another library, called Assetic, which follows this philosophy but allows you to do much - more interesting things with those assets. For more information on + more interesting things with those assets. For more information on using Assetic see :doc:`/cookbook/assetic/asset_management`. @@ -851,13 +851,13 @@ page. From inside that contact page's template, do the following: {% block stylesheets %} {{ parent() }} - + {% endblock %} - + {# ... #} -In the child template, you simply override the ``stylesheets`` block and +In the child template, you simply override the ``stylesheets`` block and put your new stylesheet tag inside of that block. Of course, since you want to add to the parent block's content (and not actually *replace* it), you should use the ``parent()`` Twig function to include everything from the ``stylesheets`` @@ -1063,7 +1063,7 @@ Three-level Inheritance ----------------------- One common way to use inheritance is to use a three-level approach. This -method works perfectly with the three different types of templates we've just +method works perfectly with the three different types of templates that were just covered: * Create a ``app/Resources/views/base.html.twig`` file that contains the main @@ -1282,7 +1282,7 @@ pattern is to do the following:: public function indexAction() { $format = $this->getRequest()->getRequestFormat(); - + return $this->render('AcmeBlogBundle:Blog:index.'.$format.'.twig'); } diff --git a/book/testing.rst b/book/testing.rst index ff4d869d61a..6972af66b80 100644 --- a/book/testing.rst +++ b/book/testing.rst @@ -226,11 +226,11 @@ document:: request( $method, - $uri, - array $parameters = array(), - array $files = array(), - array $server = array(), - $content = null, + $uri, + array $parameters = array(), + array $files = array(), + array $server = array(), + $content = null, $changeHistory = true ) @@ -434,8 +434,8 @@ it automatically. You can examine the response and force a redirection afterwards with the ``followRedirect()`` method:: $crawler = $client->followRedirect(); - -If you want the client to automatically follow all redirects, you can + +If you want the client to automatically follow all redirects, you can force him with the ``followRedirects()`` method:: $client->followRedirects(); @@ -561,7 +561,7 @@ Just like links, you select forms with the ``selectButton()`` method:: .. note:: - Notice that we select form buttons and not forms as a form can have several + Notice that you select form buttons and not forms as a form can have several buttons; if you use the traversing API, keep in mind that you must look for a button. diff --git a/book/translation.rst b/book/translation.rst index a0f481a7267..d7211925fd5 100644 --- a/book/translation.rst +++ b/book/translation.rst @@ -21,11 +21,11 @@ the user:: The term *locale* refers roughly to the user's language and country. It can be any string that your application uses to manage translations - and other format differences (e.g. currency format). We recommended the + and other format differences (e.g. currency format). The `ISO639-1`_ *language* code, an underscore (``_``), then the `ISO3166 Alpha-2`_ *country* - code (e.g. ``fr_FR`` for French/France). + code (e.g. ``fr_FR`` for French/France) is recommended. -In this chapter, we'll learn how to prepare an application to support multiple +In this chapter, you'll learn how to prepare an application to support multiple locales and then how to create translations for multiple locales. Overall, the process has several common steps: @@ -92,7 +92,7 @@ Translation of text is done through the ``translator`` service (:class:`Symfony\\Component\\Translation\\Translator`). To translate a block of text (called a *message*), use the :method:`Symfony\\Component\\Translation\\Translator::trans` method. Suppose, -for example, that we're translating a simple message from inside a controller:: +for example, that you're translating a simple message from inside a controller:: public function indexAction() { @@ -103,7 +103,7 @@ for example, that we're translating a simple message from inside a controller:: When this code is executed, Symfony2 will attempt to translate the message "Symfony2 is great" based on the ``locale`` of the user. For this to work, -we need to tell Symfony2 how to translate the message via a "translation +you need to tell Symfony2 how to translate the message via a "translation resource", which is a collection of message translations for a given locale. This "dictionary" of translations can be created in several different formats, XLIFF being the recommended format: @@ -177,7 +177,7 @@ Sometimes, a message containing a variable needs to be translated:: However, creating a translation for this string is impossible since the translator will try to look up the exact message, including the variable portions (e.g. "Hello Ryan" or "Hello Fabien"). Instead of writing a translation -for every possible iteration of the ``$name`` variable, we can replace the +for every possible iteration of the ``$name`` variable, you can replace the variable with a "placeholder":: public function indexAction($name) @@ -227,7 +227,7 @@ is done just as before: required when translating in Twig templates, and is overall a sensible convention to follow. -As we've seen, creating a translation is a two-step process: +As you've seen, creating a translation is a two-step process: #. Abstract the message that needs to be translated by processing it through the ``Translator``. @@ -263,9 +263,9 @@ filesystem and discovered by Symfony, thanks to some conventions. Each time you create a *new* translation resource (or install a bundle that includes a translation resource), be sure to clear your cache so that Symfony can discover the new translation resource: - + .. code-block:: bash - + $ php app/console cache:clear .. index:: @@ -381,11 +381,11 @@ Symfony2 will discover these files and use them when translating either locale (i.e. to translate ``symfony2.great`` to ``Symfony2 is great``). The second method is handy because the message key won't need to be changed - in every translation file if we decide that the message should actually + in every translation file if you decide that the message should actually read "Symfony2 is really great" in the default locale. The choice of which method to use is entirely up to you, but the "keyword" - format is often recommended. + format is often recommended. Additionally, the ``php`` and ``yaml`` file formats support nested ids to avoid repeating yourself if you use keywords instead of real text for your @@ -449,7 +449,7 @@ Symfony2 will discover these files and use them when translating either Using Message Domains --------------------- -As we've seen, message files are organized into the different locales that +As you've seen, message files are organized into the different locales that they translate. The message files can also be organized further into "domains". When creating message files, the domain is the first portion of the filename. The default domain is ``messages``. For example, suppose that, for organization,