src/Controller/MagController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Mag;
  4. use App\Repository\MagRepository;
  5. use Knp\Component\Pager\PaginatorInterface;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. #[Route('/mag')]
  11. class MagController extends AbstractController
  12. {
  13.     #[Route('/'name'app_mag_index'methods: ['GET'], options: ['sitemap' => true])]
  14.     public function index(MagRepository $magRepository,PaginatorInterface $paginatorRequest $request): Response
  15.     {
  16.         $mags $paginator->paginate(
  17.             $magRepository->findBy(array(), array('date' => 'DESC')), /* query NOT result */
  18.             $request->query->getInt('page'1), /*page number*/
  19.             12 /*limit per page*/
  20.         );
  21.         return $this->render('mag/list.html.twig', [
  22.             'mags' => $mags,
  23.         ]);
  24.     }
  25.     #[Route('/{slug}'name'app_mag_show'methods: ['GET'])]
  26.     public function show(Mag $mag): Response
  27.     {
  28.         return $this->render('mag/show.html.twig', [
  29.             'mag' => $mag,
  30.         ]);
  31.     }
  32. }