首先,对不起我的英语。
我正在尝试用API平台和Symfony在我的客户实体上写一篇文章。( get工作正常)
在写这篇文章时,我发现自己犯了这个错误:
“无法为”App\Entity\Customer“生成IRI。”
这是我的实体,我认为问题来自这里,但我找不到原因。
<?php
namespace App\Entity;
use ....
/**
* @ORM\Entity(repositoryClass=CustomerRepository::class)
*/
#[ApiResource(
collectionOperations: [
'get' => ['method' => 'get'],
'post' => ['method' => 'post'],
],
itemOperations: [
'get' => ['method' => 'get'],
'put' => ['method' => 'put'],
'delete' => ['method' => 'delete'],
],
denormalizationContext: ['groups' => ['write_customer']],
normalizationContext: ['groups' => ['read_customer']],
)]
class Customer
{
......发布于 2022-03-04 23:38:19
生成IRI需要ID上的可见性,如果您有序列化组,则必须将这个组添加到id (primKey)中。
首先,确保您有一个工作良好的getId函数。然后,您可以将您的海运组添加到id中。
在这里,您可以在dokumetation中找到一个例子:https://api-platform.com/docs/core/serialization/#calculated-field
....
denormalizationContext: ['groups' => ['write_customer']],
normalizationContext: ['groups' => ['read_customer']],
....
/**
* @var int The entity Id
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
#[Groups("write_customer", read_customer)]
private $id;https://stackoverflow.com/questions/71039677
复制相似问题