在uri中使用两个标识符

问题描述 投票:0回答:1

我有一个在日期时间列上分区的表。

如果我让 ApiPlateform 获取项目,查询将检查所有分区以找到该项目。

我希望能够发送 uri 上的日期

<?php

#[ApiResource(
operations: [
new Get(uriTemplate: '/entities/{id}/{date}'),
)]
#[NeedLegacyConversion]
class Invoice
{
    protected ?string $id = null;
    protected ?\DateTime $date = null;
}

我有点迷失了。

我用

uriVariables
尝试了很多东西(太多记不清了),但没有任何效果。

我喜欢 uri 有 2 个标识符

编辑: 我能够使用 uri 上的日期时间 ApiProperty:两个属性的标识符 例如在 Get 上定义 uriVariable

但是 APIP 上有一个错误,可以在标识符上使用日期时间,但当它尝试将项目和标识符链接到generete iris 时会崩溃。它需要一个标量值但无法获取日期时间:(

php api-platform.com
1个回答
0
投票

称为复合键。我不确定 API 平台是否最终支持这一点。您可以尝试在应该是复合键的属性上添加属性:

#[ApiProperty(identifier: true)]
protected ?string $id = null;

#[ApiProperty(identifier: true)]
protected ?\DateTime $date = null;

您的 uriTemplate 已经适合此配置。

如果 APIP 尚不支持,您可以实现能够使用复合键的 Doctrine 查询扩展。

© www.soinside.com 2019 - 2024. All rights reserved.