Skip to content

Commit

Permalink
bug #9553 [FrameworkBundle] use the new request_stack service to get …
Browse files Browse the repository at this point in the history
…the Request object in the base Controller class (hhamon)

This PR was merged into the master branch.

Discussion
----------

[FrameworkBundle] use the new request_stack service to get the Request object in the base Controller class

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | ~
| License       | MIT
| Doc PR        | ~

Commits
-------

2e07338 [FrameworkBundle] use the new request_stack service to get the Request object in the base Controller class
  • Loading branch information
fabpot committed Nov 21, 2013
2 parents 95b2d02 + 2e07338 commit e49ca36
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
35 changes: 35 additions & 0 deletions UPGRADE-3.0.md
Expand Up @@ -178,6 +178,41 @@ UPGRADE FROM 2.x to 3.0

### FrameworkBundle

* The `getRequest` method of the base `Controller` class has been deprecated
since Symfony 2.4 and must be therefore removed in 3.0. The only reliable
way to get the `Request` object is to inject it in the action method.

Before:

```
namespace Acme\FooBundle\Controller;
class DemoController
{
public function showAction()
{
$request = $this->getRequest();
// ...
}
}
```

After:

```
namespace Acme\FooBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
class DemoController
{
public function showAction(Request $request)
{
// ...
}
}
```

* The `enctype` method of the `form` helper was removed. You should use the
new method `start` instead.

Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php
Expand Up @@ -180,10 +180,14 @@ public function createFormBuilder($data = null, array $options = array())
* Shortcut to return the request service.
*
* @return Request
*
* @deprecated Deprecated since version 2.4, to be removed in 3.0. Ask
* Symfony to inject the Request object into your controller
* method instead by type hinting it in the method's signature.
*/
public function getRequest()
{
return $this->container->get('request');
return $this->container->get('request_stack')->getCurrentRequest();
}

/**
Expand Down

0 comments on commit e49ca36

Please sign in to comment.