Hatte beim Updaten einer Erweiterung für den Einsatz unter Contao 5 ein ähnliches Problem:
Habe es so gelöst:
PHP-Code:
<?php
declare(strict_types=1);
namespace App\Controller\FrontendModule;
use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController;
use Contao\CoreBundle\Framework\Adapter;
use Contao\CoreBundle\Framework\ContaoFramework;
use Contao\CoreBundle\ServiceAnnotation\FrontendModule;
use Contao\Input;
use Contao\ModuleModel;
use Contao\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* @FrontendModule(TestController::TYPE, category="test_modules", template="mod_test")
*/
class TestController extends AbstractFrontendModuleController
{
public const TYPE = 'test';
protected ContaoFramework $framework;
protected ?string $item = null;
// Adapters
protected Adapter $input;
public function __construct(ContaoFramework $framework)
{
$this->framework = $framework;
// Adapters
$this->input = $this->framework->getAdapter(Input::class);
}
public function __invoke(Request $request, ModuleModel $model, string $section, array $classes = null): Response
{
// Set the item from the auto_item parameter and remove auto_item from unused route parameters
if (isset($_GET['auto_item']) && '' !== $_GET['auto_item']) {
$this->input->setGet('auto_item', $_GET['auto_item']);
}
// It's important to call Input::get('auto_item') at least once,
// otherwise Contao throws a Symfony\Component\HttpKernel\Exception\NotFoundHttpException (unused argument auto_item)
$item = $this->input->get('auto_item') ?? false;
if (!$item) {
return new Response('', Response::HTTP_NO_CONTENT);
}
$this->item = $item;
return parent::__invoke($request, $model, $section, $classes);
}
protected function getResponse(Template $template, ModuleModel $model, Request $request): Response
{
$template->foo = 'bar';
return $template->getResponse();
}
}
Lesezeichen