diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 0e56c10..3f8b996 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -10,13 +10,18 @@ use Symfony\Component\Routing\Annotation\Route; class HomeController extends AbstractController { /** - * @Route("/", name="home") + * @Route("/{page}", name="home") + * @param int $page + * @return Response */ - public function index(): Response + public function index(int $page = 0): Response { + $repo = $this->getDoctrine()->getRepository(Post::class); return $this->render('home/index.html.twig', [ 'controller_name' => 'HomeController', - 'posts' => $this->getDoctrine()->getRepository(Post::class)->findBy(array(), array('publishedAt' => 'DESC'), 5, 0) + 'posts' => $repo->findBy(array(), array('publishedAt' => 'DESC'), 5, $page*5), + 'pages' => round($repo->count(array())/5, 0, PHP_ROUND_HALF_UP), + 'page' => $page ]); } } diff --git a/templates/base.html.twig b/templates/base.html.twig index 3b2ae04..86d6ebc 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -9,7 +9,6 @@ {% set admin = false %} -