desarrolla2 / rss-client-bundle
此包已弃用且不再维护。未建议替代包。
此Bundle提供了一种获取RSS源友好的方法。
v2.0.4
2013-08-05 07:12 UTC
Requires
- php: >=5.3.2
- desarrolla2/rss-client: ~2
- symfony/framework-bundle: ~2
README
这是一个为您的网站提供RSS客户端的服务,您可以从您喜欢的信息提供者处自动添加内容到您的网站。
包安装
获取包
将其添加到您的/composer.json
文件中
"require": { ... "desarrolla2/rss-client-bundle": "2.*" },
并执行
composer update
注册包
// app/AppKernel.php <?php public function registerBundles() { return array( // ... new Desarrolla2\Bundle\RSSClientBundle\RSSClientBundle(), ); }
使用RSS包
配置提供者
您需要编辑您的config.yml文件并添加您想获取的RSS路由。
# app/config/config.yml rss_client: cache: ttl: 3600 # This is the default channels: channel_name1: - 'http://www.osukaru.es/feed/' - 'http://desarrolla2.com/feed/' channel_name2: - 'http://feeds.feedburner.com/symfony/blog' - 'http://www.symfony.es/feed/'
缓存选项是完全可选的。如果没有指定,则默认值生效。
可选:配置自定义处理器
如果您想使用自定义处理器从源中提取额外信息,也请添加指向实现ProcessorInterface
服务的"processors"键。
rss_client: processors: ["my_service_id", "my_other_service_id"]
在您的控制器中
检索服务并获取内容。
<?php class NewsController extends Controller { /** * Renders latest news * * @return array * @Route("/noticias", name="news_index") * @Template() */ public function indexAction() { $this->client = $this->get('rss_client'); return array( 'feeds' => $this->client->fetch('channel_name1'), ); } }
在您的视图中
为您的用户渲染内容
{% block content %} <section> {% for feed in feeds %} <article> <header> <a href="{{ feed.link }}" target="_blank">{{ feed.title }}</a> <time>{{ feed.pubDate | date('d/m/Y H:i') }}</time> </header> <p>{{ feed | raw }}</p> </article> {% else %} <p>Not news :(</p> {% endfor %} </section> {% endblock %}
联系方式
您可以通过twitter与我联系。
更多信息
查看RSSClient。