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

时间:2023-01-15 19:00:35

I've discovered there is a helper to aid in the parsing of RSS feeds on the Kohana framework.

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

Is there one to help create one?

有没有人帮忙创建一个?

2 个解决方案

#1


3  

Whip it up with the create() method of the Feed class in Kohana 3. You'll find the code of it at the following:

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

system/classes/kohana/feed.php

系统/类/ Kohana的/ feed.php

You'll need to define the channel information and its feed items as a minimum.

您需要至少定义频道信息及其Feed项。

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

Then plug that data into the method to generate the XML:

然后将该数据插入到方法中以生成XML:

$xml = Feed::create($info, $items);

Which will give you this when you echo it out or pass it to the relevant view:

当你回应它或将它传递给相关视图时,它会给你这个:

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

#2


1  

http://docs.kohanaphp.com/helpers/feed#create

http://docs.kohanaphp.com/helpers/feed#create

#1


3  

Whip it up with the create() method of the Feed class in Kohana 3. You'll find the code of it at the following:

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

system/classes/kohana/feed.php

系统/类/ Kohana的/ feed.php

You'll need to define the channel information and its feed items as a minimum.

您需要至少定义频道信息及其Feed项。

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

Then plug that data into the method to generate the XML:

然后将该数据插入到方法中以生成XML:

$xml = Feed::create($info, $items);

Which will give you this when you echo it out or pass it to the relevant view:

当你回应它或将它传递给相关视图时,它会给你这个:

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

#2


1  

http://docs.kohanaphp.com/helpers/feed#create

http://docs.kohanaphp.com/helpers/feed#create