Zend Paginator - How to get the first item in a paginator?

I have a paginator zend object, I want to get the first element in this paginator.

I tried $paginator->getItem(0) , but it returns the message: Message: Cannot seek to 0 which is below the offset 2 . And $ paginator-> count () is 19.

I can achieve this using foreach:

 foreach ($paginator as $item) { $entry = $item; } 

How can I get this without using foreach?

+6
source share
3 answers

This will give you the first element without using foreach:

 $first = current($paginator->getItemsByPage(1)); // Get the first item $firstCurrent = current($paginator->getCurrentItems()); // Get the first item of the current pages 
+5
source

This will count the number of subpages in the rowset:

 $paginator->count(); 

This will count the total number of elements in the rowset:

 $paginator->getTotalItemCount(); 

If you have more than one subpage, maybe you need to use the second parameter in getItem() , which is several subpages?

 $paginator->getItem(1, 1); 

BTW: getItem() not zero-based, so the first element in the set of strings is getItem(1) .

In my similar situation, I have 1 subpage, and using $paginator->getItem(1) give me the correct result

0
source

It should be

 $paginator->getCurrentItems()->current(); 
0
source

Source: https://habr.com/ru/post/905700/


All Articles