Zend_Paginator如何根据变量查询的交换工作?

第8行执行一次访存,即使更改查询变量也不会更改。

如何根据gdata feed中的起始索引执行分页功能?

代码:http://pastebin.com/rmxSP1Us

            $yt = new Zend_Gdata_YouTube();

        $limit = 12;
        $offset = ($page - 1) * $limit + 1;

        $query = "http://gdata.youtube.com/feeds/api/users/aculinario/favorites?start-index=$offset";

        $paginator = Zend_Paginator::factory($yt->getVideoFeed($query));
        $paginator->setCurrentPageNumber($page);
        $paginator->setItemCountPerPage($limit);
        $paginator->setPageRange(6);
        $this->view->paginator = $paginator;

        echo $query // query changes but paginator no, every time Zend_Paginator factory should check the returned array of getVideoFeed, but not this checking

对不起,我的英语不好,我正在尝试

最佳答案

使用快速且脏的分页器适配器,我得到了类似的工作。

值得注意的是,可能有更好,更通用的方法来实现这一目标。但是,如果您着急的话,这将使您前进。

<?php
class Lib_Paginator_Adapter_YoutubeUser implements Zend_Paginator_Adapter_Interface
{
    protected $_username;
    protected $_results;

    public function __construct($username)
    {
        $this->_username = $username;
    }

    public function getItems($offset, $itemCountPerPage)
    {
        $url = sprintf(
                '%s/%s/%s',
                Zend_Gdata_YouTube::USER_URI,
                $this->_username,
                Zend_Gdata_YouTube::UPLOADS_URI_SUFFIX
        );
        try
        {
            $query = new Zend_Gdata_Query($url);
            $query->setMaxResults($itemCountPerPage)
                ->setStartIndex($offset);
            $youtube  = new Zend_Gdata_YouTube();
            $this->_results = $youtube->getUserUploads(null, $query);
            return $this->_results;
        }
        catch (Exception $ex)
        {
            echo $ex->getMessage();
            exit;
        }
    }

    public function count()
    {
        try
        {
            $youtube  = new Zend_Gdata_YouTube();
            return $youtube->getUserUploads($this->_username)->getTotalResults()->getText();
        }
        catch (Exception $ex)
        {
            echo $ex->getMessage();
            exit;
        }
    }

}

然后在您的 Controller 中
    $page = $this->getRequest()->getParam("page");
    $limit = 10;
    $username = 'aculinario';
    $paginator = new Zend_Paginator(new Lib_Paginator_Adapter_YoutubeUser($username));
    $paginator->setItemCountPerPage($limit);
    $paginator->setPageRange(10);
    $paginator->setCurrentPageNumber($page);
    $this->view->youtubeFeed = $paginator;

关于zend-framework - Zend Paginator与Gdata Youtube,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4523990/

10-12 03:09