@@ -452,7 +452,8 @@ perform a 301 (permanent) redirect, modify the second argument::
452
452
Forwarding
453
453
~~~~~~~~~~
454
454
455
- You can also easily forward to another controller internally with the ``forward() ``
455
+ You can also easily forward to another controller internally with the
456
+ :method: `Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller::forward `
456
457
method. Instead of redirecting the user's browser, it makes an internal sub-request,
457
458
and calls the specified controller. The ``forward() `` method returns the ``Response ``
458
459
object that's returned from that controller::
@@ -492,17 +493,22 @@ value to each variable.
492
493
493
494
Like other base ``Controller `` methods, the ``forward `` method is just
494
495
a shortcut for core Symfony2 functionality. A forward can be accomplished
495
- directly via the ``http_kernel `` service and returns a ``Response ``
496
- object::
496
+ directly by duplicating the current request. When this
497
+ :ref: `sub request<http-kernel-sub-requests> ` is executed via the ``http_kernel ``
498
+ service the ``HttpKernel `` returns a ``Response `` object::
499
+
500
+ use Symfony\Component\HttpKernel/HttpKernelInterface;
501
+
502
+ $path = array(
503
+ '_controller' => 'AcmeHelloBundle:Hello:fancy',
504
+ 'name' => $name,
505
+ 'color' => 'green',
506
+ );
507
+ $request = $this->container->get('request');
508
+ $subRequest = $request->duplicate(array(), null, $path);
497
509
498
510
$httpKernel = $this->container->get('http_kernel');
499
- $response = $httpKernel->forward(
500
- 'AcmeHelloBundle:Hello:fancy',
501
- array(
502
- 'name' => $name,
503
- 'color' => 'green',
504
- )
505
- );
511
+ $response = $httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
506
512
507
513
.. index ::
508
514
single: Controller; Rendering templates
0 commit comments