8.4.2 How to use pagination?

Permalink
The old way of using pagination was with the ItemList's getPagination() which is now deprecated. It says "call the pagination factory directly". So I did - I used the function code:
$comments = new ItemList();
$comments->setItemsPerPage(10);
$factory = new PaginationFactory(\Request::getInstance());
if (method_exists($comments, 'createPaginationObject')) {
    $paginator = $comments->createPaginationObject();
    $paginator = $factory->deliverPaginationObject($comments, $paginator);
} else {
    $paginator = $factory->createPaginationObject($comments);
}
$pagination = $paginator->renderDefaultView();
$this->set('comments', $paginator->getCurrentPageResults());
$this->set('pagination', $pagination);
$this->set('paginator', $paginator);

but it says "Call to protected method createPaginationObject() from context" of the block controller.

What's wrong here?

linuxoid
 
linuxoid replied on at Permalink Reply
linuxoid
I got it!
$comments = new CommentList();
$comments->setItemsPerPage(10);
$factory = new PaginationFactory(\Request::getInstance());
$paginator = $factory->createPaginationObject($comments);
$pagination = $paginator->renderDefaultView();
$this->set('comments', $paginator->getCurrentPageResults());
$this->set('pagination', $pagination);
$this->set('paginator', $paginator);