本文介绍了如何使用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的字符串值?
发布评论