From 695dd9604cd86de658384f4c7adf391feafd9a96 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Wed, 17 Dec 2025 14:50:16 +0100 Subject: [PATCH 1/2] [Routing]: Adding hint about `_route` Page: https://symfony.com/doc/6.4/controller/forwarding.html Info is taken from https://github.com/symfony/symfony/issues/5804#issuecomment-17379777 Also switched to invokable controller syntax - even though I'm not sure if this is a good idea here... --- controller/forwarding.rst | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/controller/forwarding.rst b/controller/forwarding.rst index 8d8be859da5..a2cae1621af 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. From 9045799f46d68ba46a4cb909d578a9f2a13174c8 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Wed, 17 Dec 2025 20:19:53 +0100 Subject: [PATCH 2/2] Update controller/forwarding.rst Co-authored-by: Christian Flothmann --- controller/forwarding.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controller/forwarding.rst b/controller/forwarding.rst index a2cae1621af..77a78915ec2 100644 --- a/controller/forwarding.rst +++ b/controller/forwarding.rst @@ -13,7 +13,7 @@ from *that* controller:: public function __invoke(string $name): Response { - $response = $this->forward('OtherController::class', [ + $response = $this->forward(OtherController::class, [ 'name' => $name, 'color' => 'green', ]);