我有一个包含自定义操作名称add_voucher的实体凭证:
<?php
/**
* @ApiResource(
* collectionOperations={
* "add_voucher"={
* "access_control"="is_granted('ROLE_COMMERCIAL')",
* "method"="POST",
* "path"="/vouchers/add-new",
* "controller"=AddVoucherAction::class,
* "denormalization_context"={
* "groups"={"add_new_voucher"}
* },
* "validation_groups"={"Default", "add_voucher_validation"}
* },
* }
* )
* @ORM\Entity(repositoryClass="App\Repository\VoucherRepository", repositoryClass=VoucherRepository::class)
*/
class Voucher
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @Groups("add_new_voucher")
* @ORM\Column(type="string", length=255, unique=true)
*/
private $code;
/**
* @Groups("add_new_voucher")
* @ORM\Column(type="integer")
*/
private $discount;
/**
* @Groups("add_new_voucher")
* @ORM\Column(type="datetime")
*/
private $starts_at;
public function getDiscount()
{
return $this->discount;
}
public function setDiscount($discount): void
{
$this->discount = $discount;
}
public function getId(): ?int
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getStartsAt(): ?\DateTimeInterface
{
return $this->starts_at;
}
public function setStartsAt(\DateTimeInterface $starts_at): self
{
$this->starts_at = $starts_at;
return $this;
}
}
我将非规范化组添加到code,discount,starts_at,稍后再验证操作中的此列,因此我需要先在非规范化上下文中添加它,但大张旗鼓地只显示 代码和折扣属性
答案 0 :(得分:1)
这是因为您的 $ starts_at 属性和 getStartsAt()吸气剂的拼写组合。基本上,Symfony序列化程序使用您的getter来访问私有属性。
只需将您的财产替换为 $ starstAt 或在您的吸气剂上添加下划线即可。
看看this;