我发现有一个助手可以帮助解析 Kohana 框架上的 RSS 提要。
有没有一个可以帮助创建一个?
使用 Kohana 3 中的类的create()
方法来处理它Feed
。您将在以下位置找到它的代码:
系统/类/kohana/feed.php
$info = array(
'title' => 'Dark into the Narwhal',
'pubDate' => date("D, d M Y H:i:s T"),
'description' => 'Eating bacon, taking names and leaving fortunes',
'link' => 'http://example.com/',
'copyright' => 'The Narwhal Peon',
'language' => 'en-us',
'ttl' => '7200',
);
$items = array(
array(
'title' => 'We journey with watermelon helmets',
'link' => 'blog/journey-with-watermelon-helmets',
'description' => 'Dawn breaks and the wind follows soon after.
We have found our supplies run low.',
),
//-- and the other posts you want to include
);
然后将该数据插入到生成 XML 的方法中:
$xml = Feed::create($info, $items);
当您echo
将其输出或将其传递给相关视图时,它将为您提供:
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Dark into the Narwhal</title>
<pubDate>Fri, 21 Dec 2012 13:32:42 EST</pubDate>
<description>Eating bacon, taking names and leaving fortunes</description>
<link>http://example.com/</link>
<copyright>The Narwhal Peon</copyright>
<language>en-us</language>
<ttl>7200</ttl>
<generator>KohanaPHP</generator>
<item>
<title>We journey with watermelon helmets</title>
<link>http://example.com/blog/journey-with-watermelon-helmets</link>
<description>Dawn breaks and the wind follows soon after.
We have found our supplies run low.</description>
</item>
<!-- the other posts will be here -->
</channel>
</rss>