Php Zend Paginator 1

Php Zend Paginator 1,php,zend-framework,pagination,Php,Zend Framework,Pagination,因此,我将ZF与条令一起使用,并尝试使用如下分页: $d = Zend_Paginator::factory($this->items->displayItems(['page' => 1]),'Array'); $d->setCurrentPageNumber(1); var_dump($d->getPages()); 但是我需要一种方法来设置分页器的总页数,因为我传递的数组每页总是包含10个项目,有什么方法可以做到这一点吗?我需要它才

因此,我将ZF与条令一起使用,并尝试使用如下分页:

    $d =  Zend_Paginator::factory($this->items->displayItems(['page' => 1]),'Array');
    $d->setCurrentPageNumber(1);
    var_dump($d->getPages());
但是
我需要一种方法来设置分页器的总页数
,因为我传递的数组每页总是包含10个项目,有什么方法可以做到这一点吗?我需要它才能让分页器工作,因为现在正在显示:

object(stdClass)#285 (12) { ["pageCount"]=> int(1) ["itemCountPerPage"]=> int(10) ["first"]=> int(1) ["current"]=> int(1) ["last"]=> int(1) ["pagesInRange"]=> array(1) { [1]=> int(1) } ["firstPageInRange"]=> int(1) ["lastPageInRange"]=> int(1) ["currentItemCount"]=> int(10) ["totalItemCount"]=> int(10) ["firstItemNumber"]=> int(1) ["lastItemNumber"]=> int(10) }
如您所见,
pageCount
为1,表中有100多个项目


我没有为分页器找到任何类似于
->setToalPagesCount()
的方法,有没有办法设置类似的内容?

如果您试图设置每页的项目,这是一种方法:

$paginator->setItemCountPerPage( ItemsPerPage );

因此我找到了一个解决方案,解决方案是创建我自己的分页器适配器,并添加
setCount
方法,这样我就可以提供总计数。您可以使用我拥有的
Bisna
名称空间,因此路径是:
library\Bisna\Application\Paginator\Array

<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Paginator
 * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id$
 */

/**
 * @see Zend_Paginator_Adapter_Interface
 */
require_once 'Zend/Paginator/Adapter/Interface.php';

/**
 * @category   Zend
 * @package    Zend_Paginator
 * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Bisna_Application_Paginator_Array implements Zend_Paginator_Adapter_Interface
{
    /**
     * Array
     *
     * @var array
     */
    protected $_array = null;

    /**
     * Item count
     *
     * @var integer
     */
    protected $_count = null;

    /**
     * Constructor.
     *
     * @param array $array Array to paginate
     */
    public function __construct(array $array)
    {
        $this->_array = $array;
    }

    /**
     * Returns an array of items for a page.
     *
     * @param  integer $offset Page offset
     * @param  integer $itemCountPerPage Number of items per page
     * @return array
     */
    public function getItems($offset, $itemCountPerPage)
    {
        return array_slice($this->_array, $offset, $itemCountPerPage);
    }

    /**
     * @param $count
     */
    public function setCount($count){
        $this->_count = $count;
    }

    /**
     * Returns the total number of rows in the array.
     *
     * @return integer
     */
    public function count()
    {
        return $this->_count;
    }
}

不,算总数,我确实找到了一个解决方案,我将把它作为答案发布。
$adapter = new Bisna_Application_Paginator_Array($this->items->list('pass arguments with the active page number'));
$adapter->setCount(1000); //maybe use another query from db here to calculate the total amount of pages
$paginator = new Zend_Paginator($adapter);