@@ -246,7 +246,7 @@ The controller for this can take several arguments::
246
246
// ...
247
247
}
248
248
249
- Notice that both placeholder variables (``{{ first_name}} ``, ``{{ last_name} } ``)
249
+ Notice that both placeholder variables (``{first_name} ``, ``{last_name} ``)
250
250
as well as the default ``color `` variable are available as arguments in the
251
251
controller. When a route is matched, the placeholder variables are merged
252
252
with the ``defaults `` to make one array that's available to your controller.
@@ -395,7 +395,7 @@ perform a 301 (permanent) redirect, modify the second argument::
395
395
.. tip ::
396
396
397
397
The ``redirect() `` method is simply a shortcut that creates a ``Response ``
398
- object that specializes in redirecting the user. It's equivalent to:
398
+ object that specializes in redirecting the user. It's equivalent to::
399
399
400
400
use Symfony\Component\HttpFoundation\RedirectResponse;
401
401
@@ -502,7 +502,7 @@ Accessing other Services
502
502
When extending the base controller class, you can access any Symfony2 service
503
503
via the ``get() `` method. Here are several common services you might need::
504
504
505
- $request = $this->get('request' );
505
+ $request = $this->getRequest( );
506
506
507
507
$response = $this->get('response');
508
508
@@ -574,7 +574,7 @@ by using the native PHP sessions.
574
574
Storing and retrieving information from the session can be easily achieved
575
575
from any controller::
576
576
577
- $session = $this->get('request' )->getSession();
577
+ $session = $this->getRequest( )->getSession();
578
578
579
579
// store an attribute for reuse during a later user request
580
580
$session->set('foo', 'bar');
@@ -603,7 +603,7 @@ Let's show an example where we're processing a form submit::
603
603
604
604
public function updateAction()
605
605
{
606
- if ('POST' === $this->get('request' )->getMethod()) {
606
+ if ('POST' === $this->getRequest( )->getMethod()) {
607
607
// do some sort of processing
608
608
609
609
$this->get('session')->setFlash('notice', 'Your changes were saved!');
@@ -675,7 +675,7 @@ The Request Object
675
675
Besides the values of the routing placeholders, the controller also has access
676
676
to the ``Request `` object when extending the base ``Controller `` class::
677
677
678
- $request = $this->get('request' );
678
+ $request = $this->getRequest( );
679
679
680
680
$request->isXmlHttpRequest(); // is it an Ajax request?
681
681
@@ -688,6 +688,17 @@ to the ``Request`` object when extending the base ``Controller`` class::
688
688
Like the ``Response `` object, the request headers are stored in a ``HeaderBag ``
689
689
object and are easily accessible.
690
690
691
+ .. tip ::
692
+
693
+ The ``Request `` object can also be injected as a parameter of an *action *::
694
+
695
+ use Symfony\Component\HttpFoundation\Request;
696
+
697
+ public function indexAction(Request $request)
698
+ {
699
+ $name = $request->cookies->get('name');
700
+ }
701
+
691
702
.. index ::
692
703
single: Controller; Overview
693
704
0 commit comments