diff --git a/controller/forwarding.rst b/controller/forwarding.rst index 8d8be859da5..77a78915ec2 100644 --- a/controller/forwarding.rst +++ b/controller/forwarding.rst @@ -11,9 +11,9 @@ and calls the defined controller. The ``forward()`` method returns the :class:`Symfony\\Component\\HttpFoundation\\Response` object that is returned from *that* controller:: - public function index(string $name): Response + public function __invoke(string $name): Response { - $response = $this->forward('App\Controller\OtherController::fancy', [ + $response = $this->forward(OtherController::class, [ 'name' => $name, 'color' => 'green', ]); @@ -26,10 +26,16 @@ from *that* controller:: The array passed to the method becomes the arguments for the resulting controller. The target controller method might look something like this:: - public function fancy(string $name, string $color): Response + public function __invoke(string $name, string $color): Response { // ... create and return a Response object } Like when creating a controller for a route, the order of the arguments of the -``fancy()`` method doesn't matter: the matching is done by name. +target method doesn't matter: the matching is done by name. + +.. note:: + + Twig's ``app.current_route`` will be empty after such a ``->forward()``. + But you can set its value manually by adding an array key ``_route`` to + `forward()```s second argument.