pagination post
continuous-integration/drone/push Build is passing Details

pull/9/head
Matis MAZINGUE 11 months ago
parent e5d265cc98
commit 7268375b4a

@ -14,11 +14,12 @@ class PostController extends AbstractController
#[Route('/', name: 'app_posts')] #[Route('/', name: 'app_posts')]
public function index(PostRepository $repository, Request $request): Response public function index(PostRepository $repository, Request $request): Response
{ {
$posts = $repository->findPaginatedPosts($request->query->getInt('page',1), 10); $page = $request->query->getInt('page',1);
$posts = $repository->findPaginatedPosts($page, 10);
return $this->render('post/index.html.twig', [ return $this->render('post/index.html.twig', [
'posts' => $posts, 'posts' => $posts,
'maxPosts' => $request->query->getInt('page',1) * 10, 'maxPosts' => $page * 10,
'currentPage' => $request->query->getInt('maxPosts',1) / 10 'currentPage' => $page
]); ]);
} }
} }

@ -16,7 +16,7 @@
{% for post in posts.iterator %} {% for post in posts.iterator %}
<div class="card" style="width: 42rem; margin: 20px 0 50px 100px;"> <div class="card" style="width: 42rem; margin: 20px 0 50px 100px;">
<div class="card-body"> <div class="card-body">
<h5 class="card-title">User</h5> <h5 class="card-title">User</h5><a class="btn btn-primary" href="/post/edit">crayon</a>
<h6 class="card-subtitle mb-2 text-muted">{{ post.foundDate | date("d/m/Y \\à H \\h") }}</h6> <h6 class="card-subtitle mb-2 text-muted">{{ post.foundDate | date("d/m/Y \\à H \\h") }}</h6>
<p class="card-subtitle mb-2 text-muted">{{ post.latitude }}, {{ post.longitude }}, {{ post.altitude }}m</p> <p class="card-subtitle mb-2 text-muted">{{ post.latitude }}, {{ post.longitude }}, {{ post.altitude }}m</p>
<p class="card-text">{{ post.commentary }}</p> <p class="card-text">{{ post.commentary }}</p>
@ -30,13 +30,7 @@
{% if posts.count > maxPosts %} {% if posts.count > maxPosts %}
<a class="btn btn-primary" href="/?page" id="load-more" style="margin: 20px 0 50px 100px;">Load More</a> <a class="btn btn-primary" href="/?page={{currentPage+1}}" id="load-more" style="margin: 20px 0 50px 100px;">Load More</a>
{% endif %} {% endif %}
<script>
const loadMoreBtn = document.getElementById('load-more');
loadMoreBtn.addEventListener('click', function() {
{{maxPosts}} += 10;
});
</script>
{% endblock %} {% endblock %}

Loading…
Cancel
Save