我正在使用zend框架及其paginator来获取页面中的数组。每件事情都运作良好,但我对分页器的工作方式有疑问。 首先,这是我的代码示例:
$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
时,我得到了我的阵列!
它是如何工作的?在PHP中是否有像__tostring()
这样的函数来执行这些转换?
答案 0 :(得分:3)
Zend_Paginator
实现IteratorAggregate接口,允许观察foreach
行为。
来源:Zend_Paginator – Usage – Rendering pages with view scripts