ricardosierra / rss
Laravel 5 的 RSS 构建
2.0.1
2020-06-06 01:16 UTC
Requires
- php: >=7.0.0
- illuminate/support: 4.*|5.*|6.*|7.*
README
Laravel 4 的 RSS 构建
安装
将 ricardosierra/rss
添加到 composer.json
文件中。
"ricardosierra/rss": "~2.0"
运行 composer update
以拉取 RSS 的最新版本。
现在打开 app/config/app.php
文件,并将服务提供者添加到您的 providers
数组中。
'providers' => array(
'RicardoSierra\Rss\RssServiceProvider',
)
现在添加别名。
'aliases' => array(
'Rss' => 'RicardoSierra\Rss\RssFacade',
)
用法
返回馈送
Route::get('/', function()
{
$feed = Rss::feed('2.0', 'UTF-8');
$feed->channel(array('title' => 'Channel\'s title', 'description' => 'Channel\'s description', 'link' => 'http://www.test.com/'));
for ($i=1; $i<=5; $i++){
$feed->item(array('title' => 'Item '.$i, 'description|cdata' => 'Description '.$i, 'link' => 'http://www.test.com/article-'.$i));
}
return Response::make($feed, 200, array('Content-Type' => 'text/xml'));
});
保存馈送
Route::get('/', function()
{
$feed = Rss::feed('2.0', 'UTF-8');
$feed->channel(array('title' => 'Channel\'s title', 'description' => 'Channel\'s description', 'link' => 'http://www.test.com/'));
for ($i=1; $i<=5; $i++){
$feed->item(array('title' => 'Item '.$i, 'description|cdata' => 'Description '.$i, 'link' => 'http://www.test.com/article-'.$i));
}
$feed->save('test.xml');
});