使 Kohana ORM 结果对象适合 RSS 帮助器

发布于 2024-12-21 00:14:48 字数 697 浏览 3 评论 0原文

如何使 Kohana 中返回的 ORM 结果对象适合在 RSS feed 助手的 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);

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最美不过初阳 2024-12-28 00:14:48

我将离开 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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文