如何使用PHP获取MongoID的字符串值? [英] How do you get the string value of a MongoID using PHP?
本文介绍了如何使用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的字符串值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文