Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions docs/dev/guides/backend-routes.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,39 @@ and is configured through annotations.
// src/Controller/BackendController.php
namespace App\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment as TwigEnvironment;

/**
* @Route("/contao", defaults={
* "_scope" = "backend",
* "_token_check" = true,
* "_backend_module" = "my-modules"
* })
* @Route("/contao//my-backend-route",
* name="app.backend-route"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* name="app.backend-route"
* name=App\Action\BackendAction::class,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have never seen a route with a class name, not sure this works (and is best practice?)

Copy link
Contributor

@fritzmg fritzmg Jan 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this works and is much more useful as you can then simply write

$this->router->generate(BackendAction::class)

in PHP.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a trailing comma missing after name="" which leads to AnnotationException.php line 42: [Syntax Error] Expected Doctrine\Common\Annotations\DocLexer::T_CLOSE_PARENTHESIS, got 'defaults' error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* name="app.backend-route"
* name=App\Controller\BackendController::class

* defaults={
* "_scope" = "backend",
* "_token_check" = true,
* "_backend_module" = "my-modules"
* }
* )
*/
class BackendController extends AbstractController
{
private $twig;

public function __construct(TwigEnvironment $twig)
{
$this->twig = $twig;
}

/**
* @Route("/my-backend-route", name="app.backend-route")
* @Template("my_backend_route.html.twig")
* @Route("", name="app.backend-route")
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole annotation block is not needed anymore, is it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be removed.

public function backendRouteAction()
public function __invoke()
{
return [];
return new Response($this->twig->render(
'my_backend_route.html.twig',
[]
));
}
}
```
Expand All @@ -61,8 +73,8 @@ you need to set this to true, in order to get it to work.
the current route in order to highlight the currently active node in the back end menu.
More on this later.

Be sure to have imported your bundles Controllers in your `routing.yml` *before*
the `ContaoCoreBundle` routes.
Be sure to have imported your bundles Controllers in your `routing.yml` *before*
the `ContaoCoreBundle` routes.

```yaml
# config/routing.yml
Expand Down Expand Up @@ -92,7 +104,7 @@ which must be placed into `/templates`.
{% endblock %}
```

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

* `headline`: This block renders the headline of the document.
Expand Down