Skip to content

Commit 6af97ec

Browse files
committed
Add an example to the invokable controllers section
1 parent c11dd62 commit 6af97ec

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

controller/service.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,22 @@ Invokable Controllers
8080

8181
If your controller implements the ``__invoke()`` method - popular with the
8282
Action-Domain-Response (ADR) pattern, you can simply refer to the service id
83-
(``AppBundle\Controller\HelloController`` or ``app.hello_controller`` for example).
83+
(e.g. ``AppBundle\Controller\HelloController`` or ``app.hello_controller``)::
84+
85+
// src/AppBundle/Controller/Hello.php
86+
use Symfony\Component\HttpFoundation\Response;
87+
use Symfony\Component\Routing\Annotation\Route;
88+
89+
/**
90+
* @Route("/hello/{name}", name="hello", service="AppBundle\Controller\Hello")
91+
*/
92+
class Hello
93+
{
94+
public function __invoke($name = 'World')
95+
{
96+
return new Response(sprintf('Hello %s!', $name));
97+
}
98+
}
8499

85100
Alternatives to base Controller Methods
86101
---------------------------------------

0 commit comments

Comments
 (0)