src/Controller/Front/BlogController.php line 64

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Post;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use DateTime;
  9. class BlogController extends AbstractController
  10. {
  11.     /**
  12.      * @Route("/blog", name="page_blog")
  13.      * Method ({"GET", "POST"})
  14.      */
  15.     public function index(Request $request): Response
  16.     {
  17.         $em $this->getDoctrine()->getManager();
  18.         $page $request->get('page'1);
  19.         $limit $request->get('limit'9);
  20.         $keywords $request->get('keywords''');
  21.         $date = ($request->get('date'null)) ? DateTime::createFromFormat('d/m/Y'$request->get('date'null))->setTime(000) : null;
  22.         $posts $em->getRepository(Post::class)->search($page$limit$keywords$date);
  23.         return $this->render('front/blog/index.html.twig', [
  24.             'posts' => $posts,
  25.             'page' => ($page+1),
  26.             'limit' => $limit
  27.         ]);
  28.     }
  29.     /**
  30.      * @Route("/blog-paginate", name="page_blog_paginate", options={"expose"=true})
  31.      * Method ({"GET", "POST"})
  32.      */
  33.     public function paginate(Request $request): Response
  34.     {
  35.         $em $this->getDoctrine()->getManager();
  36.         $page $request->get('page'1);
  37.         $limit $request->get('limit'3);
  38.         $keywords $request->get('keywords''');
  39.         $date = ($request->get('date'null)) ? DateTime::createFromFormat('d/m/Y'$request->get('date'null))->setTime(000) : null;
  40.         $posts $em->getRepository(Post::class)->search($page$limit$keywords$date);
  41.         return $this->render('front/blog/blog_ajax.html.twig', [
  42.             'posts' => $posts
  43.         ]);
  44.     }
  45.     /**
  46.      * @Route("/blog/{slug}", name="page_blog_single")
  47.      * Method ({"GET", "POST"})
  48.      */
  49.     public function show($slug): Response
  50.     {
  51.         $em $this->getDoctrine()->getManager();
  52.         $post $em->getRepository(Post::class)->findOneBySlug($slug);
  53.         return $this->render('front/blog/show.html.twig', [
  54.             'post' => $post
  55.         ]);
  56.     }
  57. }