内置Kohana方法,以协助开发RSS提要

时间:2009-06-02 04:43:05

标签: php rss kohana

我发现有一个助手可以帮助解析Kohana框架上的RSS提要。

是否有人帮助创建一个?

2 个答案:

答案 0 :(得分:3)

使用Kohana中create()类的Feed方法进行鞭打3.您将在下面找到它的代码:

  

系统/类/ Kohana的/ feed.php

您需要define the channel information and its feed items as a minimum

$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>

答案 1 :(得分:1)