Paginate posts (#9)
Squashed commit of the following: Author: matis.mazingue <matis.mazingue@etu.uca.fr> Author: clfreville2 <clement.freville2@etu.uca.fr>
This commit is contained in:
@@ -14,9 +14,23 @@ use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class PostController extends AbstractController
|
||||
{
|
||||
private const POSTS_PER_PAGE = 10;
|
||||
|
||||
#[Route('/', name: 'app_posts')]
|
||||
public function index(PostRepository $repository, Request $request): Response
|
||||
{
|
||||
$page = $request->query->getInt('page', 1);
|
||||
$posts = $repository->findPaginatedPosts($page, self::POSTS_PER_PAGE);
|
||||
$maxPage = ceil($posts->count() / self::POSTS_PER_PAGE);
|
||||
return $this->render('post/index.html.twig', [
|
||||
'posts' => $posts,
|
||||
'maxPage' => $maxPage,
|
||||
'page' => $page,
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/post', name: 'app_post_index', methods: ['GET'])]
|
||||
public function index(PostRepository $repository): Response
|
||||
public function table(PostRepository $repository): Response
|
||||
{
|
||||
$posts = $repository->findAll();
|
||||
return $this->render('post/table.html.twig', [
|
||||
|
Reference in New Issue
Block a user