Skip to content

Commit b74e349

Browse files
aschemppfritzmg
andauthored
Fix back end route controller example (#225)
* Fix back end route controller example * Apply suggestions from code review Co-Authored-By: Fritz Michael Gschwantner <[email protected]> * change route name and remove superfluous annotation Co-authored-by: Fritz Michael Gschwantner <[email protected]>
1 parent 79cd7e6 commit b74e349

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

docs/dev/guides/backend-routes.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,36 @@ and is configured through annotations.
2626
// src/Controller/BackendController.php
2727
namespace App\Controller;
2828

29-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
30-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
3129
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
30+
use Symfony\Component\Routing\Annotation\Route;
3231
use Symfony\Component\HttpFoundation\Response;
32+
use Twig\Environment as TwigEnvironment;
3333

3434
/**
35-
* @Route("/contao", defaults={
36-
* "_scope" = "backend",
37-
* "_token_check" = true,
38-
* "_backend_module" = "my-modules"
39-
* })
35+
* @Route("/contao/my-backend-route",
36+
* name=App\Controller\BackendController::class
37+
* defaults={
38+
* "_scope" = "backend",
39+
* "_token_check" = true,
40+
* "_backend_module" = "my-module"
41+
* }
42+
* )
4043
*/
4144
class BackendController extends AbstractController
4245
{
43-
/**
44-
* @Route("/my-backend-route", name="app.backend-route")
45-
* @Template("my_backend_route.html.twig")
46-
*/
47-
public function backendRouteAction()
46+
private $twig;
47+
48+
public function __construct(TwigEnvironment $twig)
4849
{
49-
return [];
50+
$this->twig = $twig;
51+
}
52+
53+
public function __invoke()
54+
{
55+
return new Response($this->twig->render(
56+
'my_backend_route.html.twig',
57+
[]
58+
));
5059
}
5160
}
5261
```
@@ -61,12 +70,12 @@ you need to set this to true, in order to get it to work.
6170
the current route in order to highlight the currently active node in the back end menu.
6271
More on this later.
6372

64-
Be sure to have imported your bundles Controllers in your `routing.yml` *before*
65-
the `ContaoCoreBundle` routes.
73+
Be sure to have imported your bundles Controllers in your `routing.yml` *before*
74+
the `ContaoCoreBundle` routes.
6675

6776
```yaml
6877
# config/routing.yml
69-
app:
78+
app.controller:
7079
resource: ../src/Controller
7180
type: annotation
7281
```
@@ -92,7 +101,7 @@ which must be placed into `/templates`.
92101
{% endblock %}
93102
```
94103

95-
As we extend from `@ContaoCore/Backend/be_page.html.twig` it is worth noting
104+
As we extend from `@ContaoCore/Backend/be_page.html.twig` it is worth noting
96105
that there are three different blocks you can currently use:
97106

98107
* `headline`: This block renders the headline of the document.

0 commit comments

Comments
 (0)