I have an ArrayCollection I would like to use as the basis of pagination. Typically, I simply use a custom DQL query with thesetFirstResult
and setMaxResults
methods, but it doesn't make much sense for me to do so since I already have the ArrayCollection of entities in hand (no point in extra DB queries).
My current skeleton is:
public function showOrdersAction($page)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$perPage = 10;
$user = $this->getUser();
$orders = $user->getPreviousOrders();
$maxPages = ceil(count($orders) / $perPage);
}
I'm just unsure how to actually progress from here.