@@ -438,7 +438,8 @@ perform a 301 (permanent) redirect, modify the second argument::
438
438
Forwarding
439
439
~~~~~~~~~~
440
440
441
- You can also easily forward to another controller internally with the ``forward() ``
441
+ You can also easily forward to another controller internally with the
442
+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::forward `
442
443
method. Instead of redirecting the user's browser, it makes an internal sub-request,
443
444
and calls the specified controller. The ``forward() `` method returns the ``Response ``
444
445
object that's returned from that controller::
@@ -478,17 +479,22 @@ value to each variable.
478
479
479
480
Like other base ``Controller `` methods, the ``forward `` method is just
480
481
a shortcut for core Symfony2 functionality. A forward can be accomplished
481
- directly via the ``http_kernel `` service and returns a ``Response ``
482
- object::
482
+ directly by duplicating the current request. When this
483
+ :ref: `sub request<http-kernel-sub-requests> ` is executed via the ``http_kernel ``
484
+ service the ``HttpKernel `` returns a ``Response `` object::
485
+
486
+ use Symfony\Component\HttpKernel/HttpKernelInterface;
487
+
488
+ $path = array(
489
+ '_controller' => 'AcmeHelloBundle:Hello:fancy',
490
+ 'name' => $name,
491
+ 'color' => 'green',
492
+ );
493
+ $request = $this->container->get('request');
494
+ $subRequest = $request->duplicate(array(), null, $path);
483
495
484
496
$httpKernel = $this->container->get('http_kernel');
485
- $response = $httpKernel->forward(
486
- 'AcmeHelloBundle:Hello:fancy',
487
- array(
488
- 'name' => $name,
489
- 'color' => 'green',
490
- )
491
- );
497
+ $response = $httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
492
498
493
499
.. index ::
494
500
single: Controller; Rendering templates
0 commit comments