src/Controller/Frontend/TalkAboutUsController.php line 25

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of Symfony Keen Template Project.
  4.  * (c) 2021 One AM SRL
  5.  */
  6. namespace App\Controller\Frontend;
  7. use App\Entity\TalkAboutUs;
  8. use App\Repository\TalkAboutUsRepository;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Keen\Attribute\Breadcrumb;
  11. use Knp\Component\Pager\PaginatorInterface;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. #[Route(path'/dicono-di-noi'name'frontend_talk_about_us_'methods: ['GET'])]
  17. class TalkAboutUsController extends AbstractController
  18. {
  19.     #[Route(path'/'name'list'methods: ['GET'])]
  20.     #[Breadcrumb('Dicono di noi')]
  21.     public function list(TalkAboutUsRepository $talkAboutUsRepositoryPaginatorInterface $paginatorRequest $request): Response
  22.     {
  23.         $qb $talkAboutUsRepository->createQueryBuilder('talkAboutUs')
  24.             ->addOrderBy('talkAboutUs.position''DESC');
  25.         $pagination $paginator->paginate(
  26.             $qb,
  27.             max(1$request->query->getInt('page'1)),
  28.             min($request->query->getInt('perPage'9), 9)
  29.         );
  30.         return $this->render('frontend/talk_about_us/index.html.twig', [
  31.             'pagination' => $pagination,
  32.         ]);
  33.     }
  34.     #[Route(path'/{slug}'name'read'methods: ['GET'])]
  35.     public function read(string $slugEntityManagerInterface $entityManager): Response
  36.     {
  37.         if (null === $article $entityManager->getRepository(TalkAboutUs::class)->findOneBy(['slug' => $slug])) {
  38.             throw $this->createNotFoundException();
  39.         }
  40.         return $this->render('frontend/talk_about_us/article.html.twig', [
  41.             'article' => $article,
  42.         ]);
  43.     }
  44. }