You can paginate any of the Cycle\ORM\Select objects using two basic methods: limit and offset. In addition to
that, the package spiral/pagination defines a set of basic interfaces which will allow you to easier integrate Cycle
into your application.
To paginate a simple User select:
$select = $orm->getRepository(User::class)->select()->orderBy('id', 'DESC');
// 10 results per page
$paginator = new \Spiral\Pagination\Paginator(10);
$paginator->paginate($select);
print_r($select->fetchAll());
The Select instance implements the Countable interface and can be used to calculate the number of records prior to the
selection:
print_r($select->count());
Paginate and count:
$paginator->withPage(2)->paginate($select)->countPages();
Please note that pagination happens on the database end. This forces you to explicitly set the result set as distinct
if relations like hasMany, manyToMany are joined to your query:
$select = $orm->getRepository(User::class)->select()->orderBy('id', 'DESC');
$select->distinct()->with('posts');
// 10 results per page
$paginator = new \Spiral\Pagination\Paginator(10);
$paginator->paginate($select);
print_r($select->fetchAll());