【问题标题】:Making the Kohana ORM result object suitable for the RSS helper使 Kohana ORM 结果对象适合 RSS 助手
【发布时间】:2011-12-12 21:59:54
【问题描述】:

如何在 Kohana 中使返回的 ORM 结果对象适合在 RSS 提要帮助程序的 items 参数中使用?

例如,如果想将我所有的用户帖子添加到提要中。

$posts = ORM::factory('posts')->find_all(); 

feed::create()中使用的items参数需要是多维数组。有没有一种简单的方法可以将返回的对象格式化为正确格式的多维数组?

这是我目前所得到的:

$items = array(); 
$info = array( 'title' => 'test feed' ); 
$posts = ORM::factory('post')->find_all(); 

foreach ($posts as $post) 
{ 
    $item = array('title' => $post->title, 
                    'summary' => $post->description, 
                    'pubDate' => $post->date); 
    $items[] = $item; 
} 

$this->request->response = Feed::create($info, $items);

【问题讨论】:

    标签: rss kohana kohana-3 kohana-orm


    【解决方案1】:

    我会离开 ORM 并使用 Query Builder 创建查询 - 它会以您需要的格式返回一个数组:

    $info = array( 'title' => 'test feed' ); 
    $posts = DB::select('title', array('description', 'summary'), array('date', 'pubDate'))->from('posts)->execute()->as_array();
    
    $this->request->response = Feed::create($info, $posts);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-21
      • 1970-01-01
      • 1970-01-01
      • 2022-12-29
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      相关资源
      最近更新 更多