PHP code example of inspirecharles / rsswriter

1. Go to this page and download the library: Download inspirecharles/rsswriter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

inspirecharles / rsswriter example snippets


'components' => [
    'cache' => [
        'class' => 'yii\caching\FileCache',
    ],
]

'modules' => [
    'rss' => [
        'class' => 'inspirecharles\rss\Rss',
        'feeds' => [
            'rss' => [
                'title' => 'Feed title',
                'description' => 'feed description',
                'link' => 'http://your.site.com/',
                'language' => 'en-US'
            ],
        ]
    ],
],

'urlManager' => [
    'rules' => [
        ['pattern' => '<id:rss>', 'route' => 'rss/default/index', 'suffix' => '.xml'],
    ],
],

...
public function beforeSave($insert)
{
    if (parent::beforeSave($insert)) {
        if ($insert) {
            $rss = Yii::$app->getModule('rss');
            $rssItem = $rss->createNewItem();

            $rssItem->title = $this->title;
            $rssItem->description = $this->description;
            $rssItem->link = Url::to($this->url, true);
            $rssItem->pubDate = time();

            return $rss->addItemToFeed('rss', $rssItem);
        }
        return true;
    }
    return false;
}

public function afterDelete()
{
    parent::afterDelete();
    $rss = Yii::$app->getModule('rss');
    
    $rss->deleteItems('rss', ['link' => Url::to($this->url, true)]);
}

php composer.phar