Parse.com检索数据PHP

时间:2015-06-03 15:16:53

标签: php parse-platform

动画 enter image description here

用户 enter image description here

我试图检索动画对象创建者的用户ID,如下所示。当我回显$ userID时,我看到一个数组 - 看起来它是指向用户对象的指针。如何从用户对象获取用户名?

或者,当我创建动画对象时,我会更好地将用户ID保存为动画类中的字符串吗?

$query = new ParseQuery("Animation");
$query->descending("createdAt");
$query->limit(2);
$results = $query->find();


for ($i = 0; $i < count($results); $i++) { 
  $object = $results[$i];
  $file = $object->get("gifFile");
  $url = $file->getURL();
  $userID = $object->get("createdBy");

这是$ userID

的转储
  

Parse \ ParseUser对象([_sessionToken:protected] =&gt;   [serverData:protected] =&gt; Array()[operationSet:protected] =&gt;排列   ()[estimatedData:Parse \ ParseObject:private] =&gt;数组()   [dataAvailability:Parse \ ParseObject:private] =&gt;数组()   [className:Parse \ ParseObject:private] =&gt; _用户   [objectId:Parse \ ParseObject:private] =&gt; xmoc179ICy   [createdAt:Parse \ ParseObject:private] =&gt;   [updatedAt:Parse \ ParseObject:private] =&gt;   [hasBeenFetched:Parse \ ParseObject:private] =&gt; )Parse \ ParseUser对象   ([_sessionToken:protected] =&gt; [serverData:protected] =&gt;数组()   [operationSet:protected] =&gt;数组()   [estimatedData:Parse \ ParseObject:private] =&gt;数组()   [dataAvailability:Parse \ ParseObject:private] =&gt;数组()   [className:Parse \ ParseObject:private] =&gt; _用户   [objectId:Parse \ ParseObject:private] =&gt; xmoc179ICy   [createdAt:Parse \ ParseObject:private] =&gt;   [updatedAt:Parse \ ParseObject:private] =&gt;   [hasBeenFetched:Parse \ ParseObject:private] =&gt; )

更新 - 工作代码:

    $query = new ParseQuery("Animation");
    $query->includeKey("createdBy");
    $query->descending("createdAt");
    $query->limit(2);
    $results = $query->find();


    for ($i = 0; $i < count($results); $i++) { 

      $object = $results[$i];
      $user = $object->get("createdBy");
      $username = $user->get("username");


      echo($username);
}

1 个答案:

答案 0 :(得分:2)

默认情况下,查询不会获取嵌套/相关对象,因此您基本上会得到一个指针。

尝试查看ParseQuery::includeKey()