Skip to content

Commit 968391e

Browse files
ckwalshweaverryan
authored andcommitted
Better describing controllers
1 parent 06c3bac commit 968391e

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

quick_tour/the_big_picture.rst

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ controller, referenced by the ``_controller`` value.
218218
Controllers
219219
~~~~~~~~~~~
220220

221-
The controller is responsible for returning a representation of the resource
222-
(most of the time an HTML one) and it is defined as a PHP class:
221+
The controller defines actions to handle users requests and prepares responses
222+
(often in HTML).
223223

224224
.. code-block:: php
225225
:linenos:
@@ -243,21 +243,22 @@ The controller is responsible for returning a representation of the resource
243243
244244
The code is pretty straightforward but let's explain it line by line:
245245

246-
* *line 3*: Symfony2 takes advantage of new PHP 5.3 features and as such, all
247-
controllers are properly namespaced (the namespace is the first part of the
248-
``_controller`` routing value: ``HelloBundle``).
246+
* *line 3*: Symfony2 takes advantage of new PHP 5.3 namespacing features, and
247+
all controllers should be properly namespaced. Per the routing file above,
248+
the namespace is the first part of the ``_controller`` routing value:
249+
``HelloBundle``).
249250

250-
* *line 7*: The controller name is the concatenation of the second part of the
251-
``_controller`` routing value (``Hello``) and ``Controller``. It extends the
252-
built-in ``Controller`` class, which provides useful shortcuts (as we will
253-
see later in this tutorial).
251+
* *line 7*: The controller name is the combination of the second part of the
252+
``_controller`` routing value (``Hello``) and the word ``Controller``. It
253+
extends the built-in ``Controller`` class, which provides useful shortcuts
254+
(as we will see later in this tutorial).
254255

255-
* *line 9*: Each controller is made of several actions. As per the
256+
* *line 9*: Each controller is made of several actions. As per the routing
256257
configuration, the hello page is handled by the ``index`` action (the third
257258
part of the ``_controller`` routing value). This method receives the
258-
resource placeholder values as arguments (``$name`` in our case).
259+
placeholder values as arguments (``$name`` in our case).
259260

260-
* *line 11*: The ``render()`` method loads and renders a template
261+
* *line 11*: The ``render()`` method loads and renders a template file
261262
(``HelloBundle:Hello:index.html.twig``) with the variables passed as a
262263
second argument.
263264

@@ -267,6 +268,12 @@ organized in bundles. In Symfony2 speak, a bundle is a structured set of files
267268
feature (a blog, a forum, ...) and which can be easily shared with other
268269
developers. In our example, we only have one bundle, ``HelloBundle``.
269270

271+
.. tip::
272+
273+
In general, controller actions should be as short as possible. If one is
274+
getting too long, consider refactoring some of the more complicated code to
275+
the service layer (which will be discussed later).
276+
270277
Templates
271278
~~~~~~~~~
272279

0 commit comments

Comments
 (0)