繁体   English   中英

API 平台 - 没有为资源类型定义标识符

[英]API Platform - No identifiers defined for resource of type

我有一个由 iso_code 属性标识的 Doctrine 实体 Class:

/**
 * @ApiResource(
 *     graphql={
 *          "item_query",
 *          "collection_query"
 *     }
 * )
 *
 * @ORM\Entity(repositoryClass="App\Repository\LanguageRepository")
 * @ORM\HasLifecycleCallbacks
 */
class Language extends BaseEntity
{
    /**
     * @var string
     * @ApiProperty(identifier=true)
     *
     * @ORM\Id()
     * @ORM\Column(type="string", length=2, unique=true)
     */
    private $iso_code;

    public function getId(): string
    {
        return $this->iso_code;
    }

    public function getIsoCode(): string
    {
        return $this->iso_code;
    }
}

当我尝试通过 GET 请求/api/v2/languages?pages=1访问列表时,我收到"No identifiers defined for resource of type \"App\\Entity\\Language\""错误。

当我尝试通过 GET 请求/api/v2/languages/en访问项目时,我得到了Invalid identifier value or configuration

配置: - api 平台 v2.5.6 - php 7.4 - symfony 4.4

通过在 getter function 顶部设置标识符 @ApiProperty(identifier=true) 解决了类似问题

将标识符的名称更改为$id就可以了。

但我不明白为什么不能使用$iso_code

你必须添加

App\Entity\Language
  properties: 
    id: 
      identifier: false
    iso_code:
      identifier: true 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM