문제

I`m using zend framework and its paginator to get an array in to pages. every thing work well but I have a question about the way paginator works. First this is my code sample :

  $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;
    }

when I use var_dump function it show sth like this :

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

and when I use Foreach I get my array! How does it work? Is there any function like __tostring() in PHP which does these conversions ?

도움이 되었습니까?

해결책

Zend_Paginator implements the IteratorAggregate interface, which allows observed foreach behavior.

Source: Zend_Paginator – Usage – Rendering pages with view scripts

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top