首页 > 解决方案 > FosRestBundle 单个数组和可选的关联数组

问题描述

我有一个关于@FOSRest\RequestParam. 我如何提供可选选项来请求批量更改。

例如:

$postValue = [
  'record_id' => 1234,
  'content' => "test",
  'ttl' => 0,
  'prio' => 0,
];

VS

$postValue = [
  [
  'record_id' => 1234,
  'content' => "test",
  'ttl' => 0,
  'prio' => 0,
  ],
  [
  'record_id' => 1234,
  'content' => "test",
  'ttl' => 0,
  'prio' => 0,
  ]
];

RequestParam 设置如下:

 * @FOSRest\RequestParam(name="record_id", allowBlank=false, requirements={"rule" = "\d+", "error_message" = "record_id must be an integer"}, strict=true, nullable=false, description="Record id")
 * @FOSRest\RequestParam(name="content", allowBlank=true, default="", description="Content")
 * @FOSRest\RequestParam(name="ttl", allowBlank=true, requirements={"rule" = "\d+", "error_message" = "ttl must be an integer"}, default={}, description="Time to live")
 * @FOSRest\RequestParam(name="priority", allowBlank=true, requirements={"rule" = "\d+", "error_message" = "priority must be an integer"}, default={}, description="Priority")

我知道使用 amap=true可以用于第二个示例。但是有没有办法检查使用了两个示例中的哪一个并根据数组的类型获取参数?

我可以解决这个问题,Request $request但这是我的最后一个解决方案。

希望你们知道一个解决方案:)

标签: phpapisymfonysymfony4fosrestbundle

解决方案


推荐阅读