@@ -84,20 +84,53 @@ Controllers can also define a single action using the ``__invoke()`` method,
84
84
which is a common practice when following the `ADR pattern `_
85
85
(Action-Domain-Responder)::
86
86
87
- // src/Controller/Hello.php
88
- use Symfony\Component\HttpFoundation\Response;
89
- use Symfony\Component\Routing\Annotation\Route;
87
+ .. configuration-block ::
90
88
91
- /**
92
- * @Route("/hello/{name}", name="hello")
93
- */
94
- class Hello
95
- {
96
- public function __invoke($name = 'World')
89
+ .. code-block :: php-annotations
90
+
91
+ // src/Controller/Hello.php
92
+ use Symfony\Component\HttpFoundation\Response;
93
+ use Symfony\Component\Routing\Annotation\Route;
94
+
95
+ /**
96
+ * @Route("/hello/{name}", name="hello")
97
+ */
98
+ class Hello
97
99
{
98
- return new Response(sprintf('Hello %s!', $name));
100
+ public function __invoke($name = 'World')
101
+ {
102
+ return new Response(sprintf('Hello %s!', $name));
103
+ }
99
104
}
100
- }
105
+
106
+ .. code-block :: yaml
107
+
108
+ # app/config/routing.yml
109
+ hello :
110
+ path : /hello/{name}
111
+ defaults : { _controller: app.hello_controller }
112
+
113
+ .. code-block :: xml
114
+
115
+ <!-- app/config/routing.xml -->
116
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
117
+ <routes xmlns =" http://symfony.com/schema/routing"
118
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
119
+ xsi : schemaLocation =" http://symfony.com/schema/routing
120
+ https://symfony.com/schema/routing/routing-1.0.xsd" >
121
+
122
+ <route id =" hello" path =" /hello/{name}" >
123
+ <default key =" _controller" >app.hello_controller</default >
124
+ </route >
125
+
126
+ </routes >
127
+
128
+ .. code-block :: php
129
+
130
+ // app/config/routing.php
131
+ $collection->add('hello', new Route('/hello', [
132
+ '_controller' => 'app.hello_controller',
133
+ ]));
101
134
102
135
Alternatives to base Controller Methods
103
136
---------------------------------------
0 commit comments