Skip to content

Commit 00b403c

Browse files
Update controller.rst
This update addresses some grammar issues and improves readability of the documentation.
1 parent e0a86d1 commit 00b403c

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

controller.rst

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ to render the content of a page.
2121
A Simple Controller
2222
-------------------
2323

24-
While a controller can be any PHP callable (a function, method on an object,
24+
While a controller can be any PHP callable (function, method on an object,
2525
or a ``Closure``), a controller is usually a method inside a controller
2626
class::
2727

@@ -46,7 +46,7 @@ class::
4646
}
4747
}
4848

49-
The controller is the ``number()`` method, which lives inside a
49+
The controller is the ``number()`` method, which lives inside the
5050
controller class ``LuckyController``.
5151

5252
This controller is pretty straightforward:
@@ -91,9 +91,9 @@ For more information on routing, see :doc:`/routing`.
9191
The Base Controller Class & Services
9292
------------------------------------
9393

94-
To make life nicer, Symfony comes with an optional base controller class called
94+
To aid development, Symfony comes with an optional base controller class called
9595
:class:`Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController`.
96-
You can extend it to get access to some `helper methods`_.
96+
It can be extended to gain access to `helper methods`_.
9797

9898
Add the ``use`` statement atop your controller class and then modify
9999
``LuckyController`` to extend it:
@@ -354,8 +354,8 @@ The Request object as a Controller Argument
354354
-------------------------------------------
355355

356356
What if you need to read query parameters, grab a request header or get access
357-
to an uploaded file? All of that information is stored in Symfony's ``Request``
358-
object. To get it in your controller, add it as an argument and
357+
to an uploaded file? That information is stored in Symfony's ``Request``
358+
object. To access it in your controller, add it as an argument and
359359
**type-hint it with the Request class**::
360360

361361
use Symfony\Component\HttpFoundation\Request;
@@ -531,13 +531,13 @@ the ``Request`` class::
531531
The ``Request`` class has several public properties and methods that return any
532532
information you need about the request.
533533

534-
Like the ``Request``, the ``Response`` object has also a public ``headers`` property.
535-
This is a :class:`Symfony\\Component\\HttpFoundation\\ResponseHeaderBag` that has
536-
some nice methods for getting and setting response headers. The header names are
537-
normalized so that using ``Content-Type`` is equivalent to ``content-type`` or even
538-
``content_type``.
534+
Like the ``Request``, the ``Response`` object has a public ``headers`` property.
535+
This object is of the type :class:`Symfony\\Component\\HttpFoundation\\ResponseHeaderBag`
536+
and provides methods for getting and setting response headers. The header names are
537+
normalized. As a result, the name ``Content-Type`` is equivalent to
538+
the name ``content-type`` or ``content_type``.
539539

540-
The only requirement for a controller is to return a ``Response`` object::
540+
In Symfony, a controller is required to return a ``Response`` object::
541541

542542
use Symfony\Component\HttpFoundation\Response;
543543

@@ -548,15 +548,15 @@ The only requirement for a controller is to return a ``Response`` object::
548548
$response = new Response('<style> ... </style>');
549549
$response->headers->set('Content-Type', 'text/css');
550550

551-
There are special classes that make certain kinds of responses easier. Some of these
552-
are mentioned below. To learn more about the ``Request`` and ``Response`` (and special
551+
To facilitate this, different response objects are included to address different response types.
552+
Some of these are mentioned below. To learn more about the ``Request`` and ``Response`` (and different
553553
``Response`` classes), see the :ref:`HttpFoundation component documentation <component-http-foundation-request>`.
554554

555555
Returning JSON Response
556556
~~~~~~~~~~~~~~~~~~~~~~~
557557

558558
To return JSON from a controller, use the ``json()`` helper method. This returns a
559-
special ``JsonResponse`` object that encodes the data automatically::
559+
``JsonResponse`` object that encodes the data automatically::
560560

561561
// ...
562562
public function index()
@@ -606,13 +606,16 @@ The ``file()`` helper provides some arguments to configure its behavior::
606606
Final Thoughts
607607
--------------
608608

609-
Whenever you create a page, you'll ultimately need to write some code that
610-
contains the logic for that page. In Symfony, this is called a controller,
611-
and it's a PHP function where you can do anything in order to return the
612-
final ``Response`` object that will be returned to the user.
609+
In Symfony, a controller is usualll a class method which is used to accept requests,
610+
and return a ``Response`` object. Symfony provides an ``AbstractController`` which
611+
can be used to extend the controller class, and alllows access to some frequently used utilties
612+
such as ``render`` and ``redirectToRoute``. The ``AbstractController`` also
613+
provides the ``createNotFoundException`` utility which is used to return a page
614+
not found response.
613615

614-
To make life easier, you'll probably extend the base ``AbstractController`` class because
615-
this gives access to shortcut methods (like ``render()`` and ``redirectToRoute()``).
616+
Services are accesible in controllers by typehinting them in the arguments of the controller methods.
617+
Consequently, objects such as the ``Session`` and ``Request`` objects are injected
618+
into the controller in this manner.
616619

617620
In other articles, you'll learn how to use specific services from inside your controller
618621
that will help you persist and fetch objects from a database, process form submissions,

0 commit comments

Comments
 (0)