到目前為止,從以下幾行$records = $this->entityManager->getRepository(Translation::class)->findBy([], ['id' => 'DESC'], 1, 0);$uuid = $records[0]->getId();我可以得到以下幾行。Ramsey\Uuid\Uuid {#131 #codec: Ramsey\Uuid\Codec\StringCodec {#86 -builder: Ramsey\Uuid\Builder\DefaultUuidBuilder {#383 -converter: Ramsey\Uuid\Converter\Number\DegradedNumberConverter {#390} } } #fields: array:6 [ "time_low" => "1483fc71" "time_mid" => "66e9" "time_hi_and_version" => "4e21" "clock_seq_hi_and_reserved" => "b9" "clock_seq_low" => "50" "node" => "c6e9e6405428" ] #converter: Ramsey\Uuid\Converter\Number\DegradedNumberConverter {#390} uuid: "1483fc71-66e9"}我怎樣才能提取uuid?
2 回答

躍然一笑
TA貢獻1826條經(jīng)驗 獲得超6個贊
您可以通過Ramsey\Uuid\Uuid多種方式將 UUID 提取為字符串?;痉椒ㄊ荝amsey\Uuid\Uuid::toString(),所以對于您的代碼示例如下:
$uuid = $records[0]->getId()->toString();
對于命名約定,存在一些全部調(diào)用的包裝方法Ramsey\Uuid\Uuid::toString():
Ramsey\Uuid\Uuid::serialize()
Ramsey\Uuid\Uuid::jsonSerialize()
但是當(dāng)然你可以將整個對象轉(zhuǎn)換為字符串。

梵蒂岡之花
TA貢獻1900條經(jīng)驗 獲得超5個贊
該類實現(xiàn)了 PHP 的__toString
方法,因此您可以將對象轉(zhuǎn)換為字符串:
$uuid = (string) $records[0]->getId();
- 2 回答
- 0 關(guān)注
- 171 瀏覽
添加回答
舉報
0/150
提交
取消