Zitat von
Spooky
Arbeitest du im Debug-Modus? Wenn nicht, hast du ein composer install gemacht? Wenn doch: poste deinen Code.
Composer install gemacht. Nichts geändert. Ich arbeite nicht im Debug Modus, weiß nicht wie man in den Debug Mode kommt ohne das Backend.
src/Controller/BackendController.php
PHP-Code:
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment as TwigEnvironment;
/**
* @Route("/contao/my-backend-route",
* name=App\Controller\BackendController::class,
* defaults={
* "_scope" = "backend",
* "_token_check" = true,
* "_backend_module" = "my-module"
* }
* )
*/
class BackendController extends AbstractController
{
private $twig;
public function __construct(TwigEnvironment $twig)
{
$this->twig = $twig;
}
public function __invoke()
{
return new Response($this->twig->render(
'my_backend_route.html.twig',
[]
));
}
}
config/routing.yml
Code:
app.controller:
resource: '../src/Controller'
type: annotation
templates/my_backend_route.html.twig
Code:
{% extends "@ContaoCore/Backend/be_page.html.twig" %}
{% block headline %}
Not only the content of the `title`-tag but also the title of the content section.
{% endblock %}
{% block error %}
Will be placed within the error block.
{% endblock %}
{% block main %}
<div class="tl_listing_container">
Main Content.
</div>
{% endblock %}
src/EventListener/BackendMenuListener.php
PHP-Code:
<?php
namespace App\EventListener;
use Contao\CoreBundle\Event\MenuEvent;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RouterInterface;
class BackendMenuListener
{
protected $router;
protected $requestStack;
public function __construct(RouterInterface $router, RequestStack $requestStack)
{
$this->router = $router;
$this->requestStack = $requestStack;
}
public function onBuild(MenuEvent $event): void
{
$factory = $event->getFactory();
$tree = $event->getTree();
if ('mainMenu' !== $tree->getName()) {
return;
}
$contentNode = $tree->getChild('content');
$node = $factory
->createItem('my-modules')
->setUri($this->router->generate('app.backend-route'))
->setLabel('My Modules')
->setLinkAttribute('title', 'Title')
->setLinkAttribute('class', 'my-modules')
->setCurrent($this->requestStack->getCurrentRequest()->get('_backend_module') === 'my-modules');
$contentNode->addChild($node);
}
}
config/services.yml
Code:
services:
App\EventListener\BackendMenuListener:
arguments:
- "@router"
- "@request_stack"
tags:
- { name: kernel.event_listener, event: contao.backend_menu_build, method: onBuild, priority: -255 }
Verzeichnis.PNG