Seb33300
Seb33300

Reputation: 7566

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.

Upvotes: 5

Views: 3145

Answers (2)

Cosmin Ordean
Cosmin Ordean

Reputation: 165

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

Upvotes: -2

miltone
miltone

Reputation: 4764

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

Upvotes: 5

Related Questions