How to Embed Multiple entities into single Form Symfony2.8 #48737
Replies: 7 comments 1 reply
-
CollectionType is used when you have an array of entities. You might use it if a User can have multiple UserProfiles. Which seems unlikely. I am assuming it is a one to one relation. In which case you simply pass an array of data to your form:
|
Beta Was this translation helpful? Give feedback.
-
Does your UserProfileType have a property called 'title' and is the data class set to J1UserProfile? Perhaps you could post it as well. It looks like your UserType should work. By the way the constructor for J1LocationContactType looks very suspicious. If your code still has |
Beta Was this translation helpful? Give feedback.
-
Yes UserProfileType does not having title added in class but the entity data class in UserProfileType type that is J1UserProfile entity has the title field. My UserProfileType.php is
|
Beta Was this translation helpful? Give feedback.
-
My controller is
|
Beta Was this translation helpful? Give feedback.
-
I might be blind but I am not seeing a add('title' in your UserProfileType so it is not surprising that formLocationContact.profile.title is generating an error. Is this a legacy project you inherited with no Symfony background? Are you trying to upgrade it by more or less randomly making changes? Having And as previously mentioned, I think you might need to stop and just sort of think about what you are really trying to accomplish. |
Beta Was this translation helpful? Give feedback.
-
Hi @ahundiak in UserProfileType I do not have the add('title') because its not needed there as its present in J1UserProfile entity. But Even I am trying to access the fields that having add method in UserProfileType So if I am trying to access mobileNumber it also having the same issue. So if I am doing this
in view it still says same error. |
Beta Was this translation helpful? Give feedback.
-
This is the point where you should definitely stop and maybe work through some of the simple form examples in the docs. Make sure you are looking at the correct version in the docs. Once you understand what is wrong with the statement |
Beta Was this translation helpful? Give feedback.
-
Hi Guys,
I want to embed the multiple entities into a single Symfony2 Form and I am following following document from Symfony
https://symfony.com/doc/2.8/form/form_collections.html
1: User
2: UserProfile
So I have a Form that has default data_class is User but I need few fields from UserProfile entity as well. So I did
In ContactType.php (a form class where the data_class is User)
And then in view I am trying to get the field from UserProfile like this
But I am getting the issue
Can anyone help me in this please what is wrong here.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions