Zend Paginator 与 Gdata Youtube

发布于 2024-10-08 18:05:33 字数 923 浏览 10 评论 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

抱歉,我的英语很差,我正在尝试

How Zend_Paginator can work according to the exchange of the variable query?

In line 8 performs a single fetch and does not change even by changing the query variable.

How to do paging function in accordance with the start-index from gdata feed?

The code: 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

Sry, my poor english, i'm Trying

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瑾夏年华 2024-10-15 18:05:33

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

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

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

I got something similar working using a quick & dirty paginator adapter.

It's worth noting there's probably nicer, more generic ways to achieve this. But this will get you going if you're in a hurry.

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

}

Then in your 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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文