-1

How do I make a returned ORM result object in Kohana suitable for use in the items parameter of the RSS feed helper?

For example, if want to add all of my user posts to the feed.

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

The items parameter used in feed::create() needs to be a multidimensional array. Is there a simple way to format the returned object as a multidimensional array in correct format?

Here's what I've got so far:

$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);
random
  • 9,774
  • 10
  • 66
  • 83
user1019144
  • 1,203
  • 2
  • 14
  • 19

1 Answers1

0

I'd leave the ORM and create the query with Query Builder - it will return an array in the format you need:

$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);
matino
  • 17,199
  • 8
  • 49
  • 58