@@ -218,8 +218,8 @@ controller, referenced by the ``_controller`` value.
218
218
Controllers
219
219
~~~~~~~~~~~
220
220
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).
223
223
224
224
.. code-block :: php
225
225
:linenos:
@@ -243,21 +243,22 @@ The controller is responsible for returning a representation of the resource
243
243
244
244
The code is pretty straightforward but let's explain it line by line:
245
245
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 ``).
249
250
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).
254
255
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
256
257
configuration, the hello page is handled by the ``index `` action (the third
257
258
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).
259
260
260
- * *line 11 *: The ``render() `` method loads and renders a template
261
+ * *line 11 *: The ``render() `` method loads and renders a template file
261
262
(``HelloBundle:Hello:index.html.twig ``) with the variables passed as a
262
263
second argument.
263
264
@@ -267,6 +268,12 @@ organized in bundles. In Symfony2 speak, a bundle is a structured set of files
267
268
feature (a blog, a forum, ...) and which can be easily shared with other
268
269
developers. In our example, we only have one bundle, ``HelloBundle ``.
269
270
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
+
270
277
Templates
271
278
~~~~~~~~~
272
279
0 commit comments