使 Kohana ORM 结果对象适合 RSS 帮助器
如何使 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将离开 ORM 并使用查询生成器创建查询 - 它将返回您需要的格式的数组:
I'd leave the ORM and create the query with Query Builder - it will return an array in the format you need: