如何正确创建 Zend Feed? [英] How do I correctly create a Zend Feed?

查看:38
本文介绍了如何正确创建 Zend Feed?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功创建了一个简单的 RSS 提要,但条目总是以未读和更新状态返回,并且每次我要求邮件更新提要时,从客户端删除的条目都会重新出现.

I have successfully created a simple RSS feed, but entries keep coming back as unread and updated, and entries deleted from the client reappear everytime I ask mail to update the feed.

我做错了什么?

我使用这个简单的函数来创建一个 rss 提要:

I use this simple function to create an rss feed:

public static function getFeed($db)
{
    $title = 'Latest feeds';
    $feedUri = '/rss/';

    //link from which feed is available
    $link = 'http://' . $_SERVER['HTTP_HOST'] . $feedUri;

    //create array according to structure defined in Zend_Feed documentation
    $feedArr = array('title' => $title,
                     'link'  => $link,
                     'description' => $title,
                     'language' => 'en-us',
                     'charset' => 'utf-8',
                   //'published' => 1237281011,
                     'generator' => 'Zend Framework Zend_Feed',
                     'entries' => array()
              );
    $itemObjs = array();
    $select = $db->select('id')->from('things')
                               ->order('createddate desc')
                               ->limit(10);
    $results = $db->fetchAll($select->__toString());
    $count = count($results);
    for($i=0;$i<$count;$i++) {
        $itemObjs[] = SiteUtil::getItemObjectInstance($db, $results[$i]['id']);
    }
    $count = count($itemObjs);
    for($i=0;$i<$count;$i++) {
        $obj = & $itemObjs[$i];
        $feedArr['entries'][] = array('title' => $obj->getSummary(),
                                      'link'    => 'http://' . $_SERVER['HTTP_HOST'] . $obj->getDetailUri(),
                                      'description' => $obj->description,
                                      'publishdate' => $obj->publishedDate,
                                      'guid' => 'http://' . $_SERVER['HTTP_HOST'] . $obj->getDetailUri()
                                      );
    }
    $feed = Zend_Feed::importArray($feedArr, 'rss');
    return $feed;
}

控制器类中的动作是:

public function rssAction()
{
    $feed = FeedUtil::getFeed($this->db);
    $feed->send();
}

为了访问提要,我将客户端指向:http://mysite.com/rss

So to access the feed, I point the client to: http://mysite.com/rss

我是用mac mail的rss客户端来测试的.提要下载得很好,显示了我在数据库中的所有 5 个项目,用于测试目的.问题如下:

I am using mac mail's rss client to test. The feed downloads just fine, showing all 5 items I have in the database for testing purposes. The problems are as follows:

1) 如果我将一个或多个项目标记为已读",然后告诉邮件更新提要,它会再次拉取所有项目,就好像我从来没有下载过它们一样.

1) If I mark one or more items as 'read' and then tell mail to update the feed, it pulls all items again as if I never downloaded them in the first place.

2) 如果我删除了一个或多个项目,它们会再次返回,未读,就像我第一次订阅提要一样.

2) If I delete one or more items they come back again, unread, again as if it were the first time I subscribed to the feed.

3) 提要总是标记为已更新.应该是这样吗?

3) Feeds are always marked as updated. Is that supposed to be the case?

是否与我正在设置的参数有关,我是否省略了某些内容,或者解决方案是否可以更微妙,例如设置 HTTP 内容标头(例如304 未修改")?

Is is something to do with the parameters I'm setting, am I omitting something, or could the solution be something more subtle like setting HTTP content headers (e.g. '304 Not Modified')?

我对 rss 的理解是,一旦某个项目从客户端被标记为已读或已删除,它就不应该再回来,这是我所追求的行为.

My understanding of rss is that once an item has been marked as read or deleted from the client, it should never come back, which is the behaviour I'm after.

请注意,'link' 和 'guid' 参数始终是唯一的,我尝试使用 'published' 和 'publishdate'(均为可选)属性只能得到相同的结果.上面的代码是我所拥有的简化版本,只显示了相关的部分,最后,是的,我已经阅读了rss 规范.

Just to note, the 'link' and 'guid' parameters are always unique, and I have tried experimenting with 'published' and 'publishdate' (both optional) attributes only get the same result. The above code is a simplified version of what I have, showing only the relevant bits, and finally, yes, I have read the rss specification.

在此先感谢您提供的任何帮助,我很乐意澄清任何问题.

Thanks in advance for any help offered here, I'll be happy to clarify any point.

推荐答案

根据 Zend Framework Doc,您必须使用 lastUpdate 参数来设置条目的最后修改日期.

According to the Zend Framework Doc, you must use the lastUpdate parameter to set the last modification date of an entry.

 'entries'     => array(
                         array(
                               [...]
                               'lastUpdate'   => 'timestamp of the publication date', // optional
                               [...]

因此发布用于提要,lastUpdate用于条目.

So published for the feed, and lastUpdate for the entries.

这篇关于如何正确创建 Zend Feed?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆