src/Controller/BrochuresController.php line 60

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Brochures;
  4. use App\Repository\BrochuresRepository;
  5. use Knp\Component\Pager\PaginatorInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. /**
  11.  * @Route("/ci/brochures")
  12.  */
  13. class BrochuresController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/", name="brochures.index")
  17.      * @param Request $request
  18.      * @param BrochuresRepository $brochuresRepository
  19.      * @param PaginatorInterface $paginator
  20.      * @return Response
  21.      */
  22.     public function index(Request $requestBrochuresRepository $brochuresRepositoryPaginatorInterface $paginator): Response
  23.     {
  24.         $brochures $paginator->paginate(
  25.             $brochuresRepository->findBy(['online' => true], ['id' => 'DESC']), /* query NOT result */
  26.             $request->query->getInt('page'1)/*page number*/,
  27.             $request->query->getInt('limit'12)/*limit per page*/
  28.         );
  29.         $brochuresAlaUne $brochuresRepository->features(8);
  30.         return $this->render('pages/internes/ci/brochures/index.html.twig', [
  31.             'title' => 'Brochures touristiques',
  32.             'brochures' => $brochures,
  33.             'brochuresAlaUne' => $brochuresAlaUne,
  34.             'menu' => "Côte d'Ivoire",
  35.             'current_page' => 'ci'
  36.         ]);
  37.     }
  38.     /**
  39.      * @Route("/{slug}/{id}", name="brochures.show")
  40.      * @param $slug
  41.      * @param Brochures $brochures
  42.      * @return Response
  43.      */
  44.     public function show($slugBrochures $brochures): Response
  45.     {
  46.         if ($brochures->getSlug() !== $slug) {
  47.             return $this->redirectToRoute('brochures.show', [
  48.                 'id' => $brochures->getId(),
  49.                 'slug' => $brochures->getSlug(),
  50.             ], 301);
  51.         }
  52.         return $this->render('pages/internes/ci/brochures/show.html.twig', [
  53.             'title' => $brochures->getName(),
  54.             'brochure' => $brochures,
  55.             'menu' => "Côte d'Ivoire",
  56.             'current_page' => 'ci'
  57.         ]);
  58.     }
  59. }