Skip to content

Commit 2e07338

Browse files
author
Hugo Hamon
committed
[FrameworkBundle] use the new request_stack service to get the Request object in the base Controller class
1 parent 8d85745 commit 2e07338

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

UPGRADE-3.0.md

+35
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,41 @@ UPGRADE FROM 2.x to 3.0
178178

179179
### FrameworkBundle
180180

181+
* The `getRequest` method of the base `Controller` class has been deprecated
182+
since Symfony 2.4 and must be therefore removed in 3.0. The only reliable
183+
way to get the `Request` object is to inject it in the action method.
184+
185+
Before:
186+
187+
```
188+
namespace Acme\FooBundle\Controller;
189+
190+
class DemoController
191+
{
192+
public function showAction()
193+
{
194+
$request = $this->getRequest();
195+
// ...
196+
}
197+
}
198+
```
199+
200+
After:
201+
202+
```
203+
namespace Acme\FooBundle\Controller;
204+
205+
use Symfony\Component\HttpFoundation\Request;
206+
207+
class DemoController
208+
{
209+
public function showAction(Request $request)
210+
{
211+
// ...
212+
}
213+
}
214+
```
215+
181216
* The `enctype` method of the `form` helper was removed. You should use the
182217
new method `start` instead.
183218

src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,14 @@ public function createFormBuilder($data = null, array $options = array())
180180
* Shortcut to return the request service.
181181
*
182182
* @return Request
183+
*
184+
* @deprecated Deprecated since version 2.4, to be removed in 3.0. Ask
185+
* Symfony to inject the Request object into your controller
186+
* method instead by type hinting it in the method's signature.
183187
*/
184188
public function getRequest()
185189
{
186-
return $this->container->get('request');
190+
return $this->container->get('request_stack')->getCurrentRequest();
187191
}
188192

189193
/**

0 commit comments

Comments
 (0)