@@ -12,12 +12,14 @@ injection like any other normal service.
1212Referencing your Service from Routing
1313-------------------------------------
1414
15- Registering your controller as a service is great, but you also need to make sure
16- that your routing references the service properly, so that Symfony knows to use it.
15+ Registering your controller as a service is the first step, but you also need to
16+ update your routing config to reference the service properly, so that Symfony
17+ knows to use it.
1718
19+ Use the ``service_id::method_name `` syntax to refer to the controller method.
1820If the service id is the fully-qualified class name (FQCN) of your controller,
19- you're done! You can use the normal `` App\Controller\HelloController::index ``
20- syntax in your routing and it will find your service.
21+ as Symfony recommends, then you can use something like:
22+ `` App\Controller\HelloController::index ``:
2123
2224.. configuration-block ::
2325
@@ -30,7 +32,7 @@ syntax in your routing and it will find your service.
3032 // ...
3133
3234 /**
33- * @Route(service="app.hello_controller ")
35+ * @Route(service="App\Controller\HelloController::index ")
3436 */
3537 class HelloController
3638 {
@@ -42,7 +44,7 @@ syntax in your routing and it will find your service.
4244 # config/routes.yaml
4345 hello :
4446 path : /hello
45- defaults : { _controller: app.hello_controller:indexAction }
47+ defaults : { _controller: App\Controller\HelloController::index }
4648
4749 .. code-block :: xml
4850
@@ -54,7 +56,7 @@ syntax in your routing and it will find your service.
5456 http://symfony.com/schema/routing/routing-1.0.xsd" >
5557
5658 <route id =" hello" path =" /hello" >
57- <default key =" _controller" >app.hello_controller:indexAction </default >
59+ <default key =" _controller" >App\Controller\HelloController::index </default >
5860 </route >
5961
6062 </routes >
@@ -63,22 +65,17 @@ syntax in your routing and it will find your service.
6365
6466 // config/routes.php
6567 $collection->add('hello', new Route('/hello', array(
66- '_controller' => 'app.hello_controller:indexAction ',
68+ '_controller' => 'App\Controller\HelloController::index ',
6769 )));
6870
69- .. note ::
70-
71- When using the ``service_id:method_name `` syntax, the method name must
72- end with the ``Action `` suffix.
73-
7471 .. _controller-service-invoke :
7572
7673Invokable Controllers
7774---------------------
7875
7976If your controller implements the ``__invoke() `` method - popular with the
8077Action-Domain-Response (ADR) pattern, you can simply refer to the service id
81- (``App\Controller\HelloController `` or `` app.hello_controller `` for example).
78+ (``App\Controller\HelloController `` for example).
8279
8380Alternatives to base Controller Methods
8481---------------------------------------
0 commit comments