【问题标题】:Built-in Kohana method to assist with developing an RSS feed内置 Kohana 方法可帮助开发 RSS 提要
【发布时间】:2009-06-02 04:43:05
【问题描述】:

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

有没有一个可以帮助创建一个?

【问题讨论】:

    标签: php rss kohana


    【解决方案1】:

    在 Kohana 3 中使用 Feed 类的 create() 方法进行处理。您可以在以下位置找到它的代码:

    系统/类/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>
    

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-08
      • 1970-01-01
      • 1970-01-01
      • 2017-02-08
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      相关资源
      最近更新 更多