0

我正在使用 zend 框架及其分页器将数组放入页面。一切都很好,但我对分页器的工作方式有疑问。首先这是我的代码示例:

  $arr=array(
            'parviz','neda','yazdgerd','hooshang'
            );
    $paginator =new  Zend_Paginator(new Zend_Paginator_Adapter_Array($arr));
    $paginator->setItemCountPerPage(5);
    $paginator->setCurrentPageNumber(1);
    var_dump($paginator);

    foreach ($paginator as $key => $value)
    {
        echo $key .'='.$value;
    }

当我使用 var_dump 函数时,它显示如下:

object(Zend_Paginator)[43]


protected '_cacheEnabled' => boolean true
  protected '_adapter' => 
    object(Zend_Paginator_Adapter_Array)[44]
      protected '_array' => 
        array
          0 => string 'parviz' (length=5)
          1 => string 'neda' (length=3)
          2 => string 'yazdgerd' (length=5)
          3 => string 'hooshang' (length=6)
      protected '_count' => int 6
  protected '_currentItemCount' => null
  protected '_currentItems' => null
  protected '_currentPageNumber' => int 1
  protected '_filter' => null
  protected '_itemCountPerPage' => int 5
  protected '_pageCount' => int 2
  protected '_pageRange' => null
  protected '_pages' => null
  protected '_view' => null

当我使用时,Foreach我得到了我的数组!它是如何工作的?有没有像__tostring()PHP 那样进行这些转换的函数?

4

1 回答 1

3

Zend_Paginator实现IteratorAggregate接口,该接口允许观察到的foreach行为。

来源:Zend_Paginator - 用法 - 使用视图脚本渲染页面

于 2013-03-17T11:47:07.017 回答