How can I create FormType in Symfony2 for converting an entity to a string and back?
I’ve done all that is saying in here but there is an error:
Expected argument of type "string", "<Vendor>\<Bundle>\Entity\User" given
How can I create a form where a text field will be converted to an user object?
Assuming
Userhas anusernamefield i would do a transform like the following. Please pay attention thattransformis forUsertostringtransform, whilereverseTransformis the opposite.Add the transformer to your form field:
Relevant code (like example you’ve cited):