解析PHP保存指针数组
问题描述:
我可能会遗漏一些简单的东西,但我想我会问这里,因为我无法找到关于保存解析php sdk指针数组的任何信息。解析PHP保存指针数组
我有一个来自组类的对象ID列表,我想将这些对象ID保存为指向我的组织类的指针数组。
try {
$query = new ParseQuery("Organization");
$query->equalTo('objectId', $objectID);
$results = $query->first($useMasterKey = true);
$groups = ParseObject::create('Organization', $data, true);
$groups->set("test1" , $groups);
$groups->save($useMasterKey = true);
$results->setArray("groups", $data);
//$results->setArray("test1", array('__type' => 'Pointer', 'className' => 'Group', 'objectId' => $data[0]));
//$results->setAssociativeArray("test1", array($groups[0]));
$results->save($useMasterKey = true);
} catch (\Exception $e){
print("An error has occurred with code: " . $e->getMessage());
}
$数据的对象组的对象ID的
任何帮助的阵列,将不胜感激。
答
好的,这是我最终如何做到这一点,如果别人遇到这种情况。
回顾过去,我们有在数据库中创建类似的输出这一功能
Comment(withoutDataWithObjectId: aPossibleObjectIdString)
有助于创造的是什么样子指针数组中的iOS应用。
[ { "__type": "Pointer", "className": "Group", "objectId": "5JbTj2k7hx" }, { "__type": "Pointer", "className": "Group", "objectId": "oo69vxrQG0" } ]
这只是从数据库中粘贴。它允许客户端以某种方式拉东西作为指针..
老实说,我不知道这是做到这一点,但我最终使用的最佳方式。
// HACK to add pointer type data into array type column.
// Value is the objectID from the groups collection.
foreach($data as $value) {
$groups[] = array(
"__type" => "Pointer",
"className" => "Group",
"objectId" => $value
);
}
try {
$query = new ParseQuery("Organization");
$query->equalTo('objectId', $objectID);
$results = $query->first($useMasterKey = true);
$results->setArray("groupPointer", $groups); // actual data that was generated ..
$results->setArray("groups", $data);
$results->save($useMasterKey = true);
} catch (\Exception $e){
print("An error has occurred with code: " . $e->getMessage());
}
见https://stackoverflow.com/a/31637825/2124535 – nathan
不做到这一点..它试图创建一个指针,当类型为数组。我们是能够与这样做iOS客户端,以及阵列类型列中的输出如下所示。“#Item”:“5JbTj2k7hx” }, { “__type”: “指针”, “类名”: “注释”, “OBJECTID”: “oo69vxrQG0” } ]'请注意,这是另一个集合,但IM尝试现在用解析php sdk来回购与组织相关的组。 – Steve