This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Yii2 Framework extension to provide functionality for consuming RSS and Atom feeds using zend-feed library.

Installs: 180

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 1


dev-master 2017-07-12 06:56 UTC

This package is not auto-updated.

Last update: 2021-10-16 02:57:41 UTC


This extension is a Yii 2 wrapper of Zend\Feed.


The preferred way to install this extension is through composer.

Either run

composer require shaposhnikoff/yii2-zend-rss

or add

"shaposhnikoff/yii2-zend-rss": "dev-master"

to the require section of your composer.json file.


Add feed component in config file

            'components' => [
                'feed' => [
                    'class' => 'yii\feed\FeedDriver',

Simple usage

Read Rss feed:

$feed = Yii::$app->feed->reader()->import('');

This will get RSS feed, parse it and return feed object. For more details you can read the official Zend-feed extention documentation:

Create Rss feed:

Create action Rss in controller

    public function actionRss()
        $feed = Yii::$app->feed->writer();
        $feed->setFeedLink('', 'rss');
        $feed->setDescription(Yii::t('app', 'Recent headlines'));
         * Add one or more entries. Note that entries must
         * be manually added once created.
        $posts = Post::find()->orderBy('id DESC')->limit(20)->all();
        foreach ($posts as $post) {
            $entry = $feed->createEntry();
            $entry->setLink(Yii::$app->urlManager->createAbsoluteUrl('/post/view', ['id' => $post->id]));
                    'uri' => $post->image,
                    'type' => 'image/jpeg',
                    'length' => filesize(Yii::getAlias('@webroot') . $post->image)
         * Render the resulting feed to Atom 1.0 and assign to $out.
         * You can substitute "atom" with "rss" to generate an RSS 2.0 feed.
        $out = $feed->export('rss');
        header('Content-type: text/xml');
        echo $out;

Then it's better to cache it with cache component:

public function behaviors()
        return [
            'cache' => [
                'only' => ['rss'],
                'class' => PageCache::className(),
                'duration' => 0,
                'dependency' => [
                    'class' => 'yii\caching\DbDependency',
                    'sql' => 'SELECT max(time_updated) as max FROM tbl_post',


Take a look at Zend-feed writer official documentation for more advanced usage of Zend-feed