Hallo,
ich versuche, contao innerhalb eines Controllers zu initialisieren
Code:
/src/Controller/AppController.php
Das sieht dann so aus:
PHP-Code:
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Annotation\Route;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\MemberModel;
#[AsController]
class AppController extends AbstractController
{
#[Route(
path: '/myroute',
name: 'myroute',
defaults: ['_scope' => 'frontend'],
)]
public function getExperts(): Response
{
$this->container->get('contao.framework')->initialize();
}
}
Ich bekomme dann folgende Fehlermeldung:
Code:
[2025-05-02T11:09:39.493586+00:00] request.CRITICAL: Uncaught PHP Exception Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: "Service "contao.framework" not found: even though it exists in the app's container, the container inside "App\Controller\AppController" is a smaller service locator that only knows about the "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage" and "twig" services. Try using dependency injection instead." at ServiceLocator.php line 133 {"exception":"[object] (Symfony\\Component\\DependencyInjection\\Exception\\ServiceNotFoundException(code: 0): Service \"contao.framework\" not found: even though it exists in the app's container, the container inside \"App\\Controller\\AppController\" is a smaller service locator that only knows about the \"http_kernel\", \"parameter_bag\", \"request_stack\", \"router\", \"security.authorization_checker\", \"security.csrf.token_manager\", \"security.token_storage\" and \"twig\" services. Try using dependency injection instead. at /home/benfolds/dgfm-website/vendor/symfony/dependency-injection/ServiceLocator.php:133)"} {"request_uri":"URI","request_method":"GET"}
Wie ist der richtige Weg? Vermutlich fehlt nur eine Kleinigkeit, um den container ordentlich zu laden?
Danke!