Seb33300 February 2016

Using ParamConverter from a $_POST request (not from URL)

Is it possible tu use the @ParamConverter annotation in Symfony2 to convert a parameter send via the $_POST request into an Entity?

All examples given in the symfony2 documentation convert entities from parameter defined in the route.

Setting something like that:

/**
 * @Route("/")
 * @ParamConverter("user", class="BvStandardServiceBundle:User", options={"id" = "userId"})
 */
public function userAction(User $user)
{
}

If I call this route with an id in the userId $_POST param, it results in:

Unable to guess how to get a Doctrine instance from the request information.

Answers


darkomen February 2016

The paramConverter of symfony run only for request param into the URL unfortunately : ParamConverter specification

Framework work directly with the URL param for search the association between param url and paramConverter. If you don't use a param into your URL, the engine symfony will don't search association with your paramConverter.

You can also view the kernel.event for this which need request for work : Class : ParamConverterListener.php


Cosmin Ordean February 2016

I use https://github.com/schmittjoh/JMSSerializerBundle to convert JSON data to Doctrine ORM entities and then save them to DB.

Post Status

Asked in February 2016
Viewed 1,745 times
Voted 12
Answered 2 times

Search




Leave an answer