5.3 PageUrlGenerator geht nicht
Moin Community,
ich versuche in Contao 5.3 in einem Template per PHP anhand einer ID einen Link zu basteln.
Bisher hatte ich immer getFrontendUrl genommen, das aber nun als deprecated eingestuft ist.
Also habe ich die neue Methode versucht, aber das will nicht so recht klappen.
Kann mir PHP Noob jemand auf die Sprünge helfen?
PHP-Code:
use Contao\CoreBundle\Routing\PageUrlGenerator;
use Contao\System;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Contao\PageModel;
$pageIndex = 4;
$page = PageModel::findByPk($pageIndex); // Seite anhand der ID laden
$urlGenerator = System::getContainer()->get(PageUrlGenerator::class);
// URL für die Seite generieren
$url = $urlGenerator->generate($page, UrlGeneratorInterface::ABSOLUTE_PATH);
echo '<a href="' . $url . '">' . htmlspecialchars($page->title) . '</a>';
request.CRITICAL: Uncaught PHP Exception Symfony\Component\DependencyInjection\Exception\Se rviceNotFoundException: "You have requested a non-existent service "Contao\CoreBundle\Routing\PageUrlGenerator"." at Container.php line 263 {"exception":"[object] (Symfony\\Component\\DependencyInjection\\Exceptio n\\ServiceNotFoundException(code: 0)