Zend Paginator - 如何获得paginator中的第一个元素?

hun*_*eox 7 php zend-framework zend-paginator

我有一个zend paginator对象,我想获得这个paginator中的第一个元素.

我试过$paginator->getItem(0)但它返回消息:Message: Cannot seek to 0 which is below the offset 2.而$ paginator-> count()是19.

我可以通过使用foreach来实现这一点:

foreach ($paginator as $item)
{
    $entry = $item;
}
Run Code Online (Sandbox Code Playgroud)

如何通过不使用foreach来获得这个?

Ili*_*ans 6

这将为您提供不使用foreach的第一个项目:

$first = current($paginator->getItemsByPage(1)); // Get the first item
$firstCurrent = current($paginator->getCurrentItems()); // Get the first item of the current pages
Run Code Online (Sandbox Code Playgroud)