1
0
Fork 0

Secure pagination

This commit is contained in:
Ethanell 2021-01-17 16:22:46 +01:00
parent e63473e5c7
commit cfe7d9339c

View file

@ -23,9 +23,15 @@ class PostController extends AbstractController
public function index(int $page = 0): Response
{
$repo = $this->getDoctrine()->getRepository(Post::class);
$pages = (int) round(count($repo->getPublished())/5, 0, PHP_ROUND_HALF_UP);
if ($page < 0) {
$page = 0;
} else if ($page > $pages) {
$page = $pages;
}
return $this->render('home/index.html.twig', [
'posts' => $repo->getPublished($page*5, 5),
'pages' => round(count($repo->getPublished())/5, 0, PHP_ROUND_HALF_UP)-1,
'pages' => $pages-1,
'page' => $page
]);
}