winkers / yii2-rss
使用数组或数据库查询创建 RSS
dev-master
2017-10-01 21:50 UTC
Requires
- yiisoft/yii2: ~2.0.0
This package is not auto-updated.
Last update: 2024-09-22 15:01:02 UTC
README
使用数组或数据库查询创建 RSS
安装
安装此扩展的首选方法是使用 composer。
运行以下命令之一
php composer.phar require --prefer-dist winkers/yii2-rss "dev-master"
或者在您的 composer.json 文件的 require 部分添加
"winkers/yii2-rss": "dev-master"
到
使用
一旦扩展安装完成,只需在您的代码中使用它即可
$rss = new \winkers\rss\Rss();
$channel = [];
$channel['title'] = 'My Title';
$channel['link'] = 'http://example.com';
$channel['description'] = 'The description will be come here.';
$channel['language'] = 'en-us';
/**
* Get data by query for RSS uses
*/
$data = (new \yii\db\Query())->select(['title', 'description'])->from('table')->all();
/**
* Get data by array for RSS uses
*/
$data = [
[
'title' => 'My Title',
'description' => 'The description will be come here.',
],
];
$channel['items'] = [];
foreach ($data as $k => $v) {
$channel['items'][] = [
'title' => $v['title'],
'description' => substr($v['content'], 0, 500),
];
}
header('Content-Type: text/xml');
echo $rss->createFeed($channel);
请注意,必须使用一种 query 或 array 方法。