动画
用户
我试图检索动画对象创建者的用户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);
}