Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 655
Seb33300 Avatar asked Oct 18 '22 16:10

Seb33300


1 Answers

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

like image 98
darkomen Avatar answered Oct 21 '22 09:10

darkomen