src/Controller/Front/CommunityController.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Community;
  4. use App\Entity\Masjid;
  5. use App\Repository\CommunityRepository;
  6. use Knp\Component\Pager\PaginatorInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. /**
  12.  * @Route("/community")
  13.  */
  14. class CommunityController extends AbstractController
  15. {
  16.     /**
  17.      * @Route("/", name="community_index", methods={"GET"})
  18.      */
  19.     public function index(CommunityRepository $communityRepository): Response
  20.     {
  21.         return $this->render('community/index.html.twig', [
  22.             'communities' => $communityRepository->findAll(),
  23.         ]);
  24.     }
  25.     /**
  26.      * @Route("/{slug}", name="community_show", methods={"GET"})
  27.      */
  28.     public function show(Community $communityRequest $requestPaginatorInterface $paginator): Response
  29.     {
  30.         $masjidsByCommunity $this->getDoctrine()
  31.             ->getRepository(Masjid::class)
  32.             ->findByCommunity($community);
  33.         $pagination $paginator->paginate(
  34.             $masjidsByCommunity/* query NOT result */
  35.             $request->query->getInt('page'1), /*page number*/
  36.             10 /*limit per page*/
  37.         );
  38.         return $this->render('community/show.html.twig', [
  39.             'community' => $community,
  40.             'masjids' => $pagination
  41.         ]);
  42.     }
  43. }