@@ -5,13 +5,13 @@ Controller
5
5
==========
6
6
7
7
A controller is a PHP function you create that takes information from the
8
- HTTP request and constructs and returns an HTTP response (as a Symfony2
8
+ HTTP request and constructs and returns an HTTP response (as a Symfony
9
9
``Response `` object). The response could be an HTML page, an XML document,
10
10
a serialized JSON array, an image, a redirect, a 404 error or anything else
11
11
you can dream up. The controller contains whatever arbitrary logic *your
12
12
application * needs to render the content of a page.
13
13
14
- See how simple this is by looking at a Symfony2 controller in action.
14
+ See how simple this is by looking at a Symfony controller in action.
15
15
The following controller would render a page that simply prints ``Hello world! ``::
16
16
17
17
use Symfony\Component\HttpFoundation\Response;
@@ -50,7 +50,7 @@ common examples:
50
50
Requests, Controller, Response Lifecycle
51
51
----------------------------------------
52
52
53
- Every request handled by a Symfony2 project goes through the same simple lifecycle.
53
+ Every request handled by a Symfony project goes through the same simple lifecycle.
54
54
The framework takes care of the repetitive tasks and ultimately executes a
55
55
controller, which houses your custom application code:
56
56
@@ -87,7 +87,7 @@ A Simple Controller
87
87
-------------------
88
88
89
89
While a controller can be any PHP callable (a function, method on an object,
90
- or a ``Closure ``), in Symfony2 , a controller is usually a single method inside
90
+ or a ``Closure ``), in Symfony , a controller is usually a single method inside
91
91
a controller object. Controllers are also called *actions *.
92
92
93
93
.. code-block :: php
@@ -117,7 +117,7 @@ a controller object. Controllers are also called *actions*.
117
117
118
118
This controller is pretty straightforward:
119
119
120
- * *line 4 *: Symfony2 takes advantage of PHP 5.3 namespace functionality to
120
+ * *line 4 *: Symfony takes advantage of PHP 5.3 namespace functionality to
121
121
namespace the entire controller class. The ``use `` keyword imports the
122
122
``Response `` class, which the controller must return.
123
123
@@ -185,8 +185,8 @@ controller and passes in ``ryan`` for the ``$name`` variable. Creating a
185
185
"page" means simply creating a controller method and associated route.
186
186
187
187
Notice the syntax used to refer to the controller: ``AcmeHelloBundle:Hello:index ``.
188
- Symfony2 uses a flexible string notation to refer to different controllers.
189
- This is the most common syntax and tells Symfony2 to look for a controller
188
+ Symfony uses a flexible string notation to refer to different controllers.
189
+ This is the most common syntax and tells Symfony to look for a controller
190
190
class called ``HelloController `` inside a bundle named ``AcmeHelloBundle ``. The
191
191
method ``indexAction() `` is then executed.
192
192
@@ -232,7 +232,7 @@ passed to that method::
232
232
233
233
The controller has a single argument, ``$name ``, which corresponds to the
234
234
``{name} `` parameter from the matched route (``ryan `` in the example). In
235
- fact, when executing your controller, Symfony2 matches each argument of
235
+ fact, when executing your controller, Symfony matches each argument of
236
236
the controller with a parameter from the matched route. Take the following
237
237
example:
238
238
@@ -369,7 +369,7 @@ Use it! See :doc:`/cookbook/templating/render_without_controller`.
369
369
The Base Controller Class
370
370
-------------------------
371
371
372
- For convenience, Symfony2 comes with a base ``Controller `` class that assists
372
+ For convenience, Symfony comes with a base ``Controller `` class that assists
373
373
with some of the most common controller tasks and gives your controller class
374
374
access to any resource it might need. By extending this ``Controller `` class,
375
375
you can take advantage of several helper methods.
@@ -393,7 +393,7 @@ Add the ``use`` statement atop the ``Controller`` class and then modify the
393
393
394
394
This doesn't actually change anything about how your controller works. In
395
395
the next section, you'll learn about the helper methods that the base controller
396
- class makes available. These methods are just shortcuts to using core Symfony2
396
+ class makes available. These methods are just shortcuts to using core Symfony
397
397
functionality that's available to you with or without the use of the base
398
398
``Controller `` class. A great way to see the core functionality in action
399
399
is to look in the
@@ -422,7 +422,7 @@ Common Controller Tasks
422
422
Though a controller can do virtually anything, most controllers will perform
423
423
the same basic tasks over and over again. These tasks, such as redirecting,
424
424
forwarding, rendering templates and accessing core services, are very easy
425
- to manage in Symfony2 .
425
+ to manage in Symfony .
426
426
427
427
.. index ::
428
428
single: Controller; Redirecting
@@ -496,15 +496,15 @@ look something like the following::
496
496
}
497
497
498
498
And just like when creating a controller for a route, the order of the arguments
499
- to ``fancyAction `` doesn't matter. Symfony2 matches the index key names
499
+ to ``fancyAction `` doesn't matter. Symfony matches the index key names
500
500
(e.g. ``name ``) with the method argument names (e.g. ``$name ``). If you
501
- change the order of the arguments, Symfony2 will still pass the correct
501
+ change the order of the arguments, Symfony will still pass the correct
502
502
value to each variable.
503
503
504
504
.. tip ::
505
505
506
506
Like other base ``Controller `` methods, the ``forward `` method is just
507
- a shortcut for core Symfony2 functionality. A forward can be accomplished
507
+ a shortcut for core Symfony functionality. A forward can be accomplished
508
508
directly by duplicating the current request. When this
509
509
:ref: `sub request <http-kernel-sub-requests >` is executed via the ``http_kernel ``
510
510
service the ``HttpKernel `` returns a ``Response `` object::
@@ -598,7 +598,7 @@ The Symfony templating engine is explained in great detail in the
598
598
Accessing other Services
599
599
~~~~~~~~~~~~~~~~~~~~~~~~
600
600
601
- When extending the base controller class, you can access any Symfony2 service
601
+ When extending the base controller class, you can access any Symfony service
602
602
via the ``get() `` method. Here are several common services you might need::
603
603
604
604
$templating = $this->get('templating');
@@ -643,7 +643,7 @@ The ``createNotFoundException()`` method creates a special ``NotFoundHttpExcepti
643
643
object, which ultimately triggers a 404 HTTP response inside Symfony.
644
644
645
645
Of course, you're free to throw any ``Exception `` class in your controller -
646
- Symfony2 will automatically return a 500 HTTP response code.
646
+ Symfony will automatically return a 500 HTTP response code.
647
647
648
648
.. code-block :: php
649
649
@@ -661,9 +661,9 @@ Both of these error pages can be customized. For details, read the
661
661
Managing the Session
662
662
--------------------
663
663
664
- Symfony2 provides a nice session object that you can use to store information
664
+ Symfony provides a nice session object that you can use to store information
665
665
about the user (be it a real person using a browser, a bot, or a web service)
666
- between requests. By default, Symfony2 stores the attributes in a cookie
666
+ between requests. By default, Symfony stores the attributes in a cookie
667
667
by using the native PHP sessions.
668
668
669
669
Storing and retrieving information from the session can be easily achieved
0 commit comments