1

I have a question about @FOSRest\RequestParam. How can i give an optional option to request a bulk change.

For example:

$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,
  ]
];

The RequestParam is set like this:

 * @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")

I know that using a map=true can be used for the 2nd example. But is there a way to check which of the two examples is used and fetch the parameters based on the type of array?

I can solve the issue with Request $request but that's my last solution.

Hope you guys know a solution :)

2
  • you can check coming array is single-dimensional or multi-dimensional. see this thread answer:- stackoverflow.com/a/37146075/4248328 Commented Aug 31, 2018 at 11:29
  • Thanks for your answer, but that's outside the @FOSRest\RequestParam. I was wondering if there is a way to achieve the same result provided by FOSRestBundle. Commented Aug 31, 2018 at 11:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.