beittil/yii2-rss
Composer 安装命令:
composer require beittil/yii2-rss
包简介
Yii2 Framework extension to provide functionality for consuming RSS and Atom feeds using zend-feed library.
关键字:
README 文档
README
Yii2 Framework extension to provide functionality for consuming RSS and Atom feeds using zend-feed library.
Installation
{
"require":
{
"yurkinx/yii2-rss": "dev-master"
}
}
Configuration
In config file
/config/web.php
Add feed component
'components' => array(
...
'feed' => array(
'class' => 'yii\feed\FeedDriver',
),
)
Simple usage
Read Rss feed:
$feed=Yii::$app->feed->reader()->import('http://exapmple.com/feed.rss');
This will get RSS feed, parse it and return feed object. For more details you can read the official Zend-feed extention documentaion: http://framework.zend.com/manual/2.2/en/modules/zend.feed.reader.html
Create Rss feed:
Create action Rss in controller
public function actionRss(){ $feed=Yii::$app->feed->writer(); $feed->setTitle(Yii::$app->params['title']); $feed->setLink('http://example.com'); $feed->setFeedLink('http://example.com/rss', 'rss'); $feed->setDescription(Yii::t('app','Recent headlines')); $feed->setGenerator('http://example.com/rss'); $feed->setDateModified(time()); /** * 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->setTitle($post->title); $entry->setLink(Yii::$app->urlManager->createAbsoluteUrl('/post/view',['id'=>$post->id])); $entry->setDateModified(intval($post->created)); $entry->setDateCreated(intval($post->created)); $entry->setContent( $post->content ); $entry->setEnclosure( [ 'uri'=>$post->image, 'type'=>'image/jpeg', 'length'=>filesize(Yii::getAlias('@webroot').$post->image) ] ); $feed->addEntry($entry); } /** * 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; die(); }
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 documentaion for more advanced usage of Zend-feed http://framework.zend.com/manual/2.2/en/modules/zend.feed.writer.html
beittil/yii2-rss 适用场景与选型建议
beittil/yii2-rss 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 06 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extension」 「atom」 「feed」 「rss」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 beittil/yii2-rss 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 beittil/yii2-rss 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 beittil/yii2-rss 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for Mutex implementation for PHP
A custom URL rule class for Yii 2 which allows to create translated URL rules
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
Simple RSS generator library for PHP 5.5 or later. clone from Bhaktaraz Bhatta ttps://github.com/bhaktaraz/php-rss-generator
Generator for Atom, JSON and RSS feeds in TYPO3
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-06-07