Skip to content

Commit 695dd96

Browse files
[Routing]: Adding hint about _route
Page: https://symfony.com/doc/6.4/controller/forwarding.html Info is taken from symfony/symfony#5804 (comment) Also switched to invokable controller syntax - even though I'm not sure if this is a good idea here...
1 parent 1b0ff1e commit 695dd96

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

controller/forwarding.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ and calls the defined controller. The ``forward()`` method returns the
1111
:class:`Symfony\\Component\\HttpFoundation\\Response` object that is returned
1212
from *that* controller::
1313

14-
public function index(string $name): Response
14+
public function __invoke(string $name): Response
1515
{
16-
$response = $this->forward('App\Controller\OtherController::fancy', [
16+
$response = $this->forward('OtherController::class', [
1717
'name' => $name,
1818
'color' => 'green',
1919
]);
@@ -26,10 +26,16 @@ from *that* controller::
2626
The array passed to the method becomes the arguments for the resulting controller.
2727
The target controller method might look something like this::
2828

29-
public function fancy(string $name, string $color): Response
29+
public function __invoke(string $name, string $color): Response
3030
{
3131
// ... create and return a Response object
3232
}
3333

3434
Like when creating a controller for a route, the order of the arguments of the
35-
``fancy()`` method doesn't matter: the matching is done by name.
35+
target method doesn't matter: the matching is done by name.
36+
37+
.. note::
38+
39+
Twig's ``app.current_route`` will be empty after such a ``->forward()``.
40+
But you can set its value manually by adding an array key ``_route`` to
41+
`forward()```s second argument.

0 commit comments

Comments
 (0)