Cursor-based pagination

To browse through the objects returned by using search, we use cursor-based pagination. Cursor-based pagination is used because of the real-time aspect of the handled data, which is a little bit different than the usual offset based pagination.

Search request properties

For limiting the number of objects returned at one time use the limit property.

To retrieve the objects after the limited number of objects, use the after property, and before property to retrieve objects before those retrieved.

We provide two additional useful properties hasNext and hasPrevious, which tell you if there are objects before or after the currently retrieved list.

Simple paginated search

$search = Pencepay_Request_CustomerSearch::build()
    ->limit(10)
    ->after('customer_uid') // or before('customer_uid')
    ->created()->greaterThanOrEqualTo(1417993999);

Handing results

Result of a search is a Collection object which contains the items themselves and several helpful properties mentioned above. Iterating is thus very easy.

$collection = Pencepay_Customer::search($search);
foreach ($collection->items as $customer) {
    $customer->uid;
}