首页 > 解决方案 > Symfony4 API 平台

问题描述

我将 Api 平台与 Symfony 4.2 捆绑在一起,但是当使用 Model Group.php 发布数据时,出现此错误:

"hydra:description": "无法为“App\Entity\Group”类型的项目生成 IRI",

我不明白这一点。

我的模型组:

<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ApiResource(iri="http://schema.org/Group")
 *
 * @ORM\Table(name="group")
 */
class Group
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $name;

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }
}

我需要你的帮助 :)

谢谢各位。

标签: symfonyapi-platform.com

解决方案


我认为表名有问题,因为“组”是 MySQL 中的保留字,尝试将表名更改为其他名称。


推荐阅读