Skip to content

Commit 43aa772

Browse files
committed
Merge branch 'added-request-usage' of github.com:dlsniper/symfony-docs into dlsniper-added-request-usage
Conflicts: book/controller.rst book/http_fundamentals.rst
2 parents ca7a069 + 6eb862b commit 43aa772

File tree

6 files changed

+27
-1
lines changed

6 files changed

+27
-1
lines changed

book/controller.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,8 @@ that's responsible for generating the HTML (or other format) for the controller.
493493
The ``renderView()`` method renders a template and returns its content. The
494494
content from the template can be used to create a ``Response`` object::
495495

496+
use Symfony\Component\HttpFoundation\Response;
497+
496498
$content = $this->renderView(
497499
'AcmeHelloBundle:Hello:index.html.twig',
498500
array('name' => $name)
@@ -708,6 +710,8 @@ The only requirement for a controller is to return a ``Response`` object. The
708710
abstraction around the HTTP response - the text-based message filled with HTTP
709711
headers and content that's sent back to the client::
710712

713+
use Symfony\Component\HttpFoundation\Response;
714+
711715
// create a simple Response with a 200 status code (the default)
712716
$response = new Response('Hello '.$name, 200);
713717

book/forms.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ user must be bound to the form. Add the following functionality to your
201201
controller::
202202

203203
// ...
204+
use Symfony\Component\HttpFoundation\Request;
204205

205206
public function newAction(Request $request)
206207
{

book/http_cache.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ its creation more manageable::
307307

308308
// ...
309309

310+
use Symfony\Component\HttpFoundation\Response;
311+
310312
$response = new Response();
311313

312314
// mark the response as either public or private
@@ -647,6 +649,8 @@ Put another way, the less you do in your application to return a 304 response,
647649
the better. The ``Response::isNotModified()`` method does exactly that by
648650
exposing a simple and efficient pattern::
649651

652+
use Symfony\Component\HttpFoundation\Response;
653+
650654
public function showAction($articleSlug)
651655
{
652656
// Get the minimum information to compute
@@ -1008,6 +1012,8 @@ Here is how you can configure the Symfony2 reverse proxy to support the
10081012

10091013
// ...
10101014
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache;
1015+
use Symfony\Component\HttpFoundation\Request;
1016+
use Symfony\Component\HttpFoundation\Response;
10111017

10121018
class AppCache extends HttpCache
10131019
{

book/http_fundamentals.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ need to check the incoming URI and execute different parts of your code dependin
363363
on that value. This can get ugly quickly::
364364

365365
// index.php
366+
use Symfony\Component\HttpFoundation\Request;
367+
use Symfony\Component\HttpFoundation\Response;
366368
$request = Request::createFromGlobals();
367369
$path = $request->getPathInfo(); // the URI path being requested
368370

@@ -457,6 +459,8 @@ the ``AcmeDemoBundle:Main:contact`` string is a short syntax that points to a
457459
specific PHP method ``contactAction`` inside a class called ``MainController``::
458460

459461
// src/Acme/DemoBundle/Controller/MainController.php
462+
use Symfony\Component\HttpFoundation\Response;
463+
460464
class MainController
461465
{
462466
public function contactAction()

book/templating.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,8 @@ you're actually using the templating engine service. For example::
988988

989989
is equivalent to::
990990

991+
use Symfony\Component\HttpFoundation\Response;
992+
991993
$engine = $this->container->get('templating');
992994
$content = $engine->render('AcmeArticleBundle:Article:index.html.twig');
993995

book/translation.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ of text (called a *message*), use the
9595
:method:`Symfony\\Component\\Translation\\Translator::trans` method. Suppose,
9696
for example, that you're translating a simple message from inside a controller::
9797

98+
// ...
99+
use Symfony\Component\HttpFoundation\Response;
100+
98101
public function indexAction()
99102
{
100103
$t = $this->get('translator')->trans('Symfony2 is great');
@@ -168,6 +171,9 @@ Message Placeholders
168171

169172
Sometimes, a message containing a variable needs to be translated::
170173

174+
// ...
175+
use Symfony\Component\HttpFoundation\Response;
176+
171177
public function indexAction($name)
172178
{
173179
$t = $this->get('translator')->trans('Hello '.$name);
@@ -181,14 +187,17 @@ will try to look up the exact message, including the variable portions
181187
for every possible iteration of the ``$name`` variable, you can replace the
182188
variable with a "placeholder"::
183189

190+
// ...
191+
use Symfony\Component\HttpFoundation\Response;
192+
184193
public function indexAction($name)
185194
{
186195
$t = $this->get('translator')->trans(
187196
'Hello %name%',
188197
array('%name%' => $name)
189198
);
190199

191-
new Response($t);
200+
return new Response($t);
192201
}
193202

194203
Symfony2 will now look for a translation of the raw message (``Hello %name%``)

0 commit comments

Comments
 (0)