<?php
namespace App\Controller\Page;
use App\Entity\Page;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class PageController extends AbstractController
{
private EntityManagerInterface $em;
public function __construct(
EntityManagerInterface $em
) {
$this->em = $em;
}
/**
* Page entry point.
*/
#[Route(path: '/page/{code}', name: 'page', methods: ['GET', 'POST'])]
public function index(Request $request, string $code): Response
{
$page = $this->em->getRepository(Page::class)->findOneByCode($code);
if (!$page) {
throw $this->createNotFoundException('This page does not exist');
}
$title = $page->getName();
$content = $page->getContent();
return $this->render('page/default.html.twig', [
'title' => $title,
'content' => $content,
]);
}
}