src/Controller/Page/PageController.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Page;
  3. use App\Entity\Page;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class PageController extends AbstractController
  10. {
  11.     private EntityManagerInterface $em;
  12.     public function __construct(
  13.         EntityManagerInterface $em
  14.     ) {
  15.         $this->em $em;
  16.     }
  17.     /**
  18.      * Page entry point.
  19.      */
  20.     #[Route(path'/page/{code}'name'page'methods: ['GET''POST'])]
  21.     public function index(Request $requeststring $code): Response
  22.     {
  23.         $page $this->em->getRepository(Page::class)->findOneByCode($code);
  24.         if (!$page) {
  25.             throw $this->createNotFoundException('This page does not exist');
  26.         }
  27.         $title $page->getName();
  28.         $content $page->getContent();
  29.         return $this->render('page/default.html.twig', [
  30.             'title' => $title,
  31.             'content' => $content,
  32.         ]);
  33.     }
  34. }