Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Paginator - How can get the first element in paginator?

I have a zend paginator 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 the $paginator->count() is 19.

I can achieve this by using foreach:

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

How can I get this by not using foreach?

like image 233
hungneox Avatar asked Jan 11 '12 10:01

hungneox


2 Answers

This will give you the first item without using foreach:

$first = current($paginator->getItemsByPage(1)); // Get the first item
$firstCurrent = current($paginator->getCurrentItems()); // Get the first item of the current pages
like image 119
Ilians Avatar answered Nov 10 '22 05:11

Ilians


It should be

$paginator->getCurrentItems()->current();
like image 35
rukavina Avatar answered Nov 10 '22 04:11

rukavina