I'm building a REST API using Symfony 2.3 & FOSRestBundle.
Do anyone know how to customize POST parameter keys, so that, for instance: "company_mybundle_user[firstName]={value}" becomes
"firstName={value}".
The latter wouldn't work because of the form validation inside "postUsersAction(Request $request)":
// src/Company/MyBundle/Controller/UserController.php
// ...
public function postUsersAction(Request $request)
{
$entity = new User();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
$view = new View($entity);
} else {
$view = View::create($form);
}
return $this->get('fos_rest.view_handler')->handle($view);
}
Thanks for your help!!
Solution found:
Empty the value returned by "UserType::getName()" will remove the prefixes of parameters. Hence "company_mybundle_user[lastName]" becomes lastName
Before:
After:
PS: make sure to clear cache before testing: