8000 Controller as service example without deprecated FrameworkExtraBundle… · symfony/symfony-docs@ce9750f · GitHub
[go: up one dir, main page]

Skip to content

Commit ce9750f

Browse files
authored
Controller as service example without deprecated FrameworkExtraBundle annotation
Improves upon #9470
1 parent 8f8ddff commit ce9750f

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

controller/service.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,26 @@ knows to use it.
1818

1919
Use the ``service_id::method_name`` syntax to refer to the controller method.
2020
If the service id is the fully-qualified class name (FQCN) of your controller,
21-
as Symfony recommends, then you can use something like:
22-
``App\Controller\HelloController::index``:
21+
as Symfony recommends, then the syntax is the same as if the controller was not
22+
a service like: ``App\Controller\HelloController::index``:
2323

2424
.. configuration-block::
2525

2626
.. code-block:: php-annotations
2727
2828
// src/Controller/HelloController.php
2929
30-
// You need to use Sensio's annotation to specify a service id
31-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
32-
// ...
30+
use Symfony\Component\Routing\Annotation\Route;
3331
34-
/**
35-
* @Route(service="App\Controller\HelloController::index")
36-
*/
3732
class HelloController
3833
{
39-
// ...
34+
/**
35+
* @Route("/hello", name="hello")
36+
*/
37+
public function index()
38+
{
39+
// ...
40+
}
4041
}
4142
4243
.. code-block:: yaml
@@ -75,7 +76,7 @@ Invokable Controllers
7576

7677
If your controller implements the ``__invoke()`` method - popular with the
7778
Action-Domain-Response (ADR) pattern, you can simply refer to the service id
78-
(``App\Controller\HelloController`` for example).
79+
without the method (``App\Controller\HelloController`` for example).
7980

8081
Alternatives to base Controller Methods
8182
---------------------------------------
@@ -89,7 +90,7 @@ The base `Controller class source code`_ is a great way to see how to accomplish
8990
common tasks. For example, ``$this->render()`` is usually used to render a Twig
9091
template and return a Response. But, you can also do this directly:
9192

92-
In a controller that's defined as a service, you can instead inject the ``templating``
93+
In a controller that's defined as a service, you can instead inject the ``twig``
9394
service and use it directly::
9495

9596
// src/Controller/HelloController.php

0 commit comments

Comments
 (0)
0