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:
@@ -5,6 +5,7 @@ namespace App\Repository;
|
||||
use App\Entity\Post;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Doctrine\ORM\Tools\Pagination\Paginator;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Post>
|
||||
@@ -16,6 +17,20 @@ class PostRepository extends ServiceEntityRepository
|
||||
parent::__construct($registry, Post::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return Paginator<Post>
|
||||
*/
|
||||
public function findPaginatedPosts(int $page, int $limit): Paginator
|
||||
{
|
||||
$query = $this->createQueryBuilder('p')
|
||||
->setFirstResult(($page - 1) * $limit)
|
||||
->setMaxResults($limit);
|
||||
|
||||
return new Paginator($query, fetchJoinCollection: false);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @return Post[] Returns an array of Post objects
|
||||
// */
|
||||
|
Reference in New Issue
Block a user