Before you can render a feed, you must first setup the data necessary for
the feed being rendered. This utilises a simple setter style API
which doubles as an initial method for validating the data being set. By design, the
API closely matches that for Zend_Feed_Reader
to avoid undue confusion and uncertainty.
Note
Users have commented that the lack of a simple array based notation for input data gives rise to lengthy tracts of code. This will be addressed in a future release.
Zend_Feed_Writer offers this API via its data
container classes Zend_Feed_Writer_Feed and
Zend_Feed_Writer_Entry (not to mention the Atom 2.0 specific
and Extension classes). These classes merely store
all feed data in a type-agnostic manner, meaning you may reuse any data
container with any renderer without requiring additional work. Both classes
are also amenable to Extensions, meaning that an Extension may define its own
container classes which are registered to the base container classes as extensions, and
are checked when any method call triggers the base container's
__call() method.
Here's a summary of the Core API for Feeds. You should note it
comprises not only the basic RSS and Atom standards, but also
accounts for a number of included Extensions bundled with
Zend_Feed_Writer. The naming of these
Extension sourced methods remain fairly generic - all Extension
methods operate at the same level as the Core API though we do allow
you to retrieve any specific Extension object separately if required.
The Feed Level API for data is contained in
Zend_Feed_Writer_Feed. In addition to the API
detailed below, the class also implements the Countable and
Iterator interfaces.
Table 72. Feed Level API Methods
setId() |
Set a unique ID associated with this feed. For Atom 1.0 this is an atom:id element, whereas for RSS 2.0 it is added as a guid element. These are optional so long as a link is added, i.e. the link is set as the ID. |
setTitle() |
Set the title of the feed. |
setDescription() |
Set the text description of the feed. |
setLink() |
Set a URI to the HTML website containing the same or similar information as this feed (i.e. if the feed is from a blog, it should provide the blog's URI where the HTML version of the entries can be read). |
setFeedLinks() |
Add a link to an XML feed, whether the feed being generated or an alternate URI pointing to the same feed but in a different format. At a minimum, it is recommended to include a link to the feed being generated so it has an identifiable final URI allowing a client to track its location changes without necessitating constant redirects. The parameter is an array of arrays, where each sub-array contains the keys "type" and "uri". The type should be one of "atom", "rss", or "rdf". |
addAuthors() |
Sets the data for authors. The parameter is an array of arrays where each sub-array may contain the keys "name", "email" and "uri". The "uri" value is only applicable for Atom feeds since RSS contains no facility to show it. For RSS 2.0, rendering will create two elements - an author element containing the email reference with the name in brackets, and a Dublin Core creator element only containing the name. |
addAuthor() |
Sets the data for a single author following the same array format as described above for a single sub-array. |
setDateCreated() |
Sets the date on which this feed was created. Generally
only applicable to Atom where it represents the date the resource
described by an Atom 1.0 document was created. The expected parameter
may be a UNIX timestamp or a
Zend_Date object.
|
setDateModified() |
Sets the date on which this feed was last modified. The expected
parameter may be a UNIX timestamp or a
Zend_Date object.
|
setLastBuildDate() |
Sets the date on which this feed was last build. The expected
parameter may be a UNIX timestamp or a
Zend_Date object. This will only be
rendered for RSS 2.0 feeds and is automatically
rendered as the current date by default when not explicity set.
|
setLanguage() |
Sets the language of the feed. This will be omitted unless set. |
setGenerator() |
Allows the setting of a generator. The parameter should be an
array containing the keys "name", "version" and "uri". If omitted
a default generator will be added referencing
Zend_Feed_Writer, the current Zend Framework
version and the Framework's URI.
|
setCopyright() |
Sets a copyright notice associated with the feed. |
addHubs() |
Accepts an array of Pubsubhubbub Hub Endpoints to be rendered in
the feed as Atom links so that PuSH Subscribers may subscribe to
your feed. Note that you must implement a Pubsubhubbub Publisher in
order for real-time updates to be enabled. A Publisher may be
implemented using
Zend_Feed_Pubsubhubbub_Publisher.
The method addHub() allows adding
a single hub at a time.
|
addCategories() |
Accepts an array of categories for rendering, where each element is
itself an array whose possible keys include "term", "label" and
"scheme". The "term" is a typically a category name suitable for
inclusion in a URI. The "label" may be a human
readable category name supporting special characters (it is
HTML encoded during rendering) and is a required key.
The "scheme" (called the domain in RSS) is optional
but must be a valid URI. The method
addCategory() allows adding a single category
at a time.
|
setImage() |
Accepts an array of image metadata for an RSS image or Atom logo. Atom 1.0 only requires a URI. RSS 2.0 requires a URI, HTML link, and an image title. RSS 2.0 optionally may send a width, height and image description. The array parameter may contain these using the keys: uri, link, title, description, height and width. The RSS 2.0 HTML link should point to the feed source's HTML page. |
createEntry() |
Returns a new instance of
Zend_Feed_Writer_Entry. This is the Entry level
data container. New entries are not automatically assigned to the
current feed, so you must explicitly call
addEntry() to add the entry for rendering.
|
addEntry() |
Adds an instance of Zend_Feed_Writer_Entry
to the current feed container for rendering.
|
createTombstone() |
Returns a new instance of
Zend_Feed_Writer_Deleted. This is the Atom 2.0
Tombstone level data container. New entries are not automatically
assigned to the current feed, so you must explicitly call
addTombstone() to add the deleted entry for
rendering.
|
addTombstone() |
Adds an instance of Zend_Feed_Writer_Deleted to
the current feed container for rendering.
|
removeEntry() |
Accepts a parameter indicating an array index of the entry to remove from the feed. |
export() |
Exports the entire data hierarchy to an XML feed. The
method has two parameters. The first is the feed type, one of "atom"
or "rss". The second is an optional boolean to set whether
Exceptions are thrown. The default is TRUE.
|
Note
In addition to these setters, there are also matching getters to retrieve data from
the Entry data container. For example, setImage() is
matched with a getImage() method.




