2011-12-12 19 views
-1

如何在Kohana中使返回的ORM結果對象適用於RSS饋送助手的items參數?使Kohana ORM結果對象適用於RSS助手

例如,如果想要將所有用戶帖子添加到供稿中。

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

回答

0

我要離開的ORM和使用查詢生成器的查詢 - 它會在格式返回一個數組,你需要:

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