How can i get the page details in controller's action? I have used the album's pagination.
$iteratorAdapter = new \Zend\Paginator\Adapter\Iterator($this->getAlbumTable()->fetchAll());
$paginator = new \Zend\Paginator\Paginator($iteratorAdapter);
$paginator->setCurrentPageNumber($page);
$paginator->setItemCountPerPage(2);
return new ViewModel(array(
'paginator' => $paginator
));
I had tried to get by using the method getPages().
$iteratorAdapter = new \Zend\Paginator\Adapter\Iterator($this->getAlbumTable()->fetchAll());
$paginator = new \Zend\Paginator\Paginator($iteratorAdapter);
$paginator->setCurrentPageNumber($page);
$paginator->setItemCountPerPage(2);
$pagingInfo = $paginator->getPages();
return new ViewModel(array(
'paginator' => $paginator,
'pagingInfo' => $pagingInfo,
));
In this case, i have 8 records in table. Perpage is 2. so, i have 4 pages. After using getPages() method, 3rd & 4th pages has no records. But pagination is exist.
What's wrong? Is there any other method to get total no of records, current page number and current page records count in controller? Please suggest me.
this is the expected bahaviour.
You have set items per page to 2, and current page to 1.
this means you will get back all items on the first page, ie. items 1 and 2.
If you want the total pages in the collection use this:
Current page number:
You are asking to get current page count in the controller, but why? You are setting this value in your controller so you must already have it (setCurrentPageNumber(..))..
If you let me know what you are trying to do maybe I can show you a better example of how to do it.