Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fetus-hina/yii2-feed
RSS/Atom feed generator. This is a wrapper for zend feed writer.
https://github.com/fetus-hina/yii2-feed
atom php rss yii2 yii2-extension
Last synced: 6 days ago
JSON representation
RSS/Atom feed generator. This is a wrapper for zend feed writer.
- Host: GitHub
- URL: https://github.com/fetus-hina/yii2-feed
- Owner: fetus-hina
- License: mit
- Created: 2018-08-20T19:54:26.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-08-21T12:10:34.000Z (about 6 years ago)
- Last Synced: 2024-10-11T05:21:19.457Z (about 1 month ago)
- Topics: atom, php, rss, yii2, yii2-extension
- Language: PHP
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
jp3cki/yii2-feed
================This is a zend feed writer wrapper for Yii 2.
You can put RSS and Atom feeds easy.License
-------[MIT License](LICENSE.md).
Copyright © 2018 AIZAWA HinaRequirements
------------- PHP 7.1+
Install
-------`composer.phar install jp3cki/yii2-feed`
Example
-------```php
namespace app\controllers;use Yii;
use yii\data\ActiveDataProvider;
use yii\helpers\Url;
use yii\web\Controller;
use yii\web\Response;use jp3cki\yii2\feed\Feed;
class FeedController extends Controller
{
public function actionRss()
{
return $this->feedResponse(
Feed::TYPE_RSS,
'application/rss+xml'
);
}public function actionAtom()
{
return $this->feedResponse(
Feed::TYPE_ATOM,
'application/atom+xml'
);
}private function feedResponse(string $type, string $contentType)
{
Yii::$app->timeZone = 'Etc/UTC'; // recommended$resp = Yii::$app->response;
$resp->format = Response::FORMAT_XML;
$resp->formatters[Response::FORMAT_XML]['contentType'] = $contentType;
$resp->data = Feed::widget([
// feed type.
'type' => $type, // Feed::TYPE_RSS or Feed::TYPE_ATOM// main data.
'dataProvider' => new ActiveDataProvider([
'query' => Article::find()->orderBy(['id' => SORT_DESC]),
'pagination' => [
'pageSize' => 10,
],
]),// channel data.
'title' => Yii::$app->name,
'description' => 'Bla bra bla...',
'copyright' => 'Copyright (C) 2018 AIZAWA Hina',
'link' => Url::home(true),
'rssLink' => Url::to(['feed/rss'], true),
'atomLink' => Url::to(['feed/atom'], true),
'author' => [
'name' => 'AIZAWA Hina',
'email' => '[email protected]',
'uri' => 'https://fetus.jp/',
],
'generator' => [
'name' => Yii::$app->name,
'version' => Yii::$app->version,
'uri' => Url::home(true),
],
'dateCreated' => null, // null means "now"
'dateModified' => null,
'lastBuildDate' => null,// entry formatters. (like GridView::$columns)
'entry' => [
// 'attrName' => 'value' or
// 'attrName' => callback function
//
// all callback prototype:
// function ($model, $key, $feedEntry, $widget): { }
'title' => function ($model): string {
return $model['title'];
},
'link' => function ($model): string {
return $model['link'];
},
'dateModified' => function ($model) {
return $model['dateModified'] ?? null;
},
'dateCreated' => function ($model) {
return $model['dateCreated'] ?? null;
},
'description' => function ($model): string {
return $model['description'];
},
'content' => function ($model): string {
return $model['content'];
},
],
]);
return $resp;
}
}
```