Documentation

RSS view

Presentation

The RSS view allows you to send feeds in RSS format, used in particular to list the content posted on a content site (such as a blog).

Usage

To use the RSS view, you must define the use of this view. In addition to that, you must assign several template variables:

  • title: (mandatory) Defines the title of the site.
  • description: (mandatory) Defines the description of the site.
  • domain: (mandatory) Defines the domain name of the site.
  • language: (optional) Defines the language of the site (or the language of the conteus listed in the RSS feed).
  • contact: (optional) Defines the contact email address of the site.
  • copyright: (optional) Copyright information.
  • category: (optional) Category of the site. Blog by default.
  • articles: Defines the list of articles to be listed in the feed. Each element of the list must be an associative array with the following keys:
    • title: (mandatory) Title of the article.
    • url: (mandatory) URL of the article.
    • pubDate: (optional) Publication date in 'YYYY-MM-DD hh:mm:ss' format.
    • abstract: (optional) Summary of the article.
    • author: (optional) Email address of the author.
    • guid: (optional) Unique identifier of the article (use its URL otherwise).

Here is an example of sending data in RSS format:

class ApiController extends \Temma\Web\Controller {
    public function getArticles() {
        $this['domain'] = 'https://mysite.com';
        $this['title'] = 'My super site';
        $this['description'] = 'Blah blah blah blah blah';
        $this['language'] = 'en';
        $this['contact'] = 'contact@mysite.com';
        $this['articles'] = [
            [
                'title'    => 'Happy new year!',
                'url'      => 'https://mysite.com/page/23',
                'pubDate'  => '2000-01-01 00:00:00',
            ],
            [
                'title'    => 'New decade',
                'url'      => 'https://mysite.com/page/734',
                'pubDate'  => '2010-01-01 00:00:00',
            ],
        ];

        // set the used view
        $this->_view('\Temma\Views\Rss');
    }
}
  • Lines 3 to 21: Definition of the data that will be transmitted to the view.
  • Line 24: We specify that the view to use for the outgoing data is the RSS view (and not the usual Smarty view).

Note: The RSS view obviously does not need templates, since it is the PHP data that is directly serialized.

The received data will look like this:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
    <link>https://mysite.com</link>
    <title>My super site</title>
    <description>Blah blah blah blah blah</description>
    <language>en</language>
    <managingEditor>contact@mysite.com</managingEditor>
    <webMaster>contact@mysite.com</webMaster>
    <generator>Temma RSS generator 1.0.0</generator>
    <category>Blog</category>
    <item>
        <title>Happy new year!</title>
        <link>https://mysite.com/page/23</link>
        <pubDate>Sat, 01 Jan 2000 00:00:00 +0100</pubDate>
    </item>
    <item>
        <title>New decade</title>
        <link>https://mysite.com/page/734</link>
        <pubDate>Fri, 01 Jan 2010 00:00:00 +0100</pubDate>
    </item>
</channel>
</rss>
Previous: CSV view
Next: INI view

Table of Contents