PHP code example of quansitech / qscmf-rssfeed

1. Go to this page and download the library: Download quansitech/qscmf-rssfeed 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/ */

    

quansitech / qscmf-rssfeed example snippets


composer 

//添加
'quansitech/qscmf-rssfeed' => [
    'feeds' => [
        'title' => '这是我的rss',  //订阅标题
        'items' => [  //被定于的数据库源
            '新闻' => [
                'model' => \Common\Model\NewsModel::class
            ],
            '活动' => [
                'model' => \Common\Model\TribuneModel::class
            ]
        ]
    ]
]

//以NewsModel为例
public function toFeedItem()
{
    //定义rss字段与数据源的字段映射
    return [
        'id' => 'id',  //必填
        'title' => 'title', //必填
        'summary' => 'content', 
        'updated' => 'publish_date', //必填
        'link' => 'link',
        'author' => 'author'
    ];
}

//这里定义取得数据条目,这里只取最新的50条
public function getFeedItems()
{
    $ents = $this->where(['status' => DBCont::NORMAL_STATUS])->order('publish_date desc')->page(1, 50)->select();
    foreach($ents as &$ent){
        $ent['link'] = U('/home/activities/detail', ['id' => $ent['id']], false, true);
    }
    return $ents;
}