获取数据存储区中的实体 ID PHP API
Get Entity's ID in Datastore PHP API
有没有办法使用 PHP 数据存储 API 获取实体的 ID/Key?
我已经验证了所有内容并且能够获取值,但没有 ID
这是我的代码:
<?php
$title = "Builder | Makeroid Account";
include "../assets/includes/head.php";
if (!$USER->is_logged_in()) {
$USER->redirect('/');
}
require_once __DIR__.'/../assets/libs/datastore/vendor/autoload.php';
use Google\Cloud\Datastore\DatastoreClient;
use Google\Cloud\Datastore\Query\Query;
$datastore = new DatastoreClient([
'projectId' => 'makeroid-builder'
]);
$query = $datastore->query();
$query->kind('UserData');
$query->filter('emaillower', '=', $U_DATA['email']);
$users = $datastore->runQuery($query);
$params = ["email", "emailFrequency", "emaillower", "isAdmin", "link", "name", "sessionid", "settings", "templatePath", "tosAccepted", "type", "upgradedGCS"];
?>
<div class="content">
<div class="container-fluid">
<div class="row">
<?php foreach ($users as $user) { ?>
<div class="col-md-12">
<div class="card">
<div class="card-header card-header-icon" data-background-color="rose">
<i class="material-icons">assignment</i>
</div>
<div class="card-content">
<h4 class="card-title">User Properties</h4>
<div class="table-responsive">
<table class="table">
<thead class="text-primary">
<th>Key</th>
<th>Value</th>
</thead>
<tbody>
<?php print_r($user); foreach ($params as $param) { ?>
<tr>
<td><?=$param?></td>
<td><?=$user?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<?php include "../assets/includes/footer.php"; ?>
我想得到这个:
我能够获取行中的所有值,例如我的电子邮件,但我没有找到获取该 ID 的方法
我试过使用 $user['id']
、$user['key']
或 $user['__key__']
,但其中 none 有效
您需要使用类似 $key->pathEndIdentifier() 的方法从实体 (https://googlecloudplatform.github.io/google-cloud-php/#/docs/google-cloud/v0.56.0/datastore/entity?method=key) then pull the id from the key (https://googlecloudplatform.github.io/google-cloud-php/#/docs/google-cloud/v0.56.0/datastore/key) 中提取密钥。
因此,与其尝试将键作为字典值从对象中提取出来,不如尝试将其作为一种方法提取出来。 $user->key()->pathEndIdentifier() .
有没有办法使用 PHP 数据存储 API 获取实体的 ID/Key?
我已经验证了所有内容并且能够获取值,但没有 ID
这是我的代码:
<?php
$title = "Builder | Makeroid Account";
include "../assets/includes/head.php";
if (!$USER->is_logged_in()) {
$USER->redirect('/');
}
require_once __DIR__.'/../assets/libs/datastore/vendor/autoload.php';
use Google\Cloud\Datastore\DatastoreClient;
use Google\Cloud\Datastore\Query\Query;
$datastore = new DatastoreClient([
'projectId' => 'makeroid-builder'
]);
$query = $datastore->query();
$query->kind('UserData');
$query->filter('emaillower', '=', $U_DATA['email']);
$users = $datastore->runQuery($query);
$params = ["email", "emailFrequency", "emaillower", "isAdmin", "link", "name", "sessionid", "settings", "templatePath", "tosAccepted", "type", "upgradedGCS"];
?>
<div class="content">
<div class="container-fluid">
<div class="row">
<?php foreach ($users as $user) { ?>
<div class="col-md-12">
<div class="card">
<div class="card-header card-header-icon" data-background-color="rose">
<i class="material-icons">assignment</i>
</div>
<div class="card-content">
<h4 class="card-title">User Properties</h4>
<div class="table-responsive">
<table class="table">
<thead class="text-primary">
<th>Key</th>
<th>Value</th>
</thead>
<tbody>
<?php print_r($user); foreach ($params as $param) { ?>
<tr>
<td><?=$param?></td>
<td><?=$user?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<?php include "../assets/includes/footer.php"; ?>
我想得到这个:
我试过使用 $user['id']
、$user['key']
或 $user['__key__']
,但其中 none 有效
您需要使用类似 $key->pathEndIdentifier() 的方法从实体 (https://googlecloudplatform.github.io/google-cloud-php/#/docs/google-cloud/v0.56.0/datastore/entity?method=key) then pull the id from the key (https://googlecloudplatform.github.io/google-cloud-php/#/docs/google-cloud/v0.56.0/datastore/key) 中提取密钥。
因此,与其尝试将键作为字典值从对象中提取出来,不如尝试将其作为一种方法提取出来。 $user->key()->pathEndIdentifier() .