0

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

在第 8 行中执行单次获取,即使更改查询变量也不会更改。

如何根据 gdata feed 的 start-index 做分页功能?

代码: 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

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

4

1 回答 1

2

我使用快速而肮脏的分页器适配器进行了类似的工作。

值得注意的是,可能有更好、更通用的方法来实现这一点。但如果你赶时间,这会让你继续前进。

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

}

然后在你的控制器中

    $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;
于 2011-06-18T10:06:58.913 回答