如何使用PHP获取MongoID的字符串值?

编程入门 行业动态 更新时间:2024-10-27 08:25:09
本文介绍了如何使用PHP获取MongoID的字符串值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

插入后,我想使用json_encode()将对象传递给客户端.问题是,不包含_id值.

After doing an insert I want to pass the object to the client using json_encode(). The problem is, the _id value is not included.

$widget = array('text' => 'Some text'); $this->mongo->db->insert($widget); If I echo $widget['_id'] the string value gets displays on the screen, but I want to do something like this: $widget['widgetId'] = $widget['_id']->id; So I can do json_encode() and include the widget id: echo json_encode($widget);

推荐答案

相信这就是你所追求的.

Believe this is what you're after.

$widget['_id']->{'$id'};

类似这样的东西.

$widget = array('text' => 'Some text'); $this->mongo->db->insert($widget); $widget['widgetId'] = $widget['_id']->{'$id'}; echo json_encode($widget);

更多推荐

如何使用PHP获取MongoID的字符串值?

本文发布于:2023-10-10 11:27:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1478536.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   字符串值   PHP   MongoID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!