I have two entity: User and Person. An user is a person and in the User entity I have a method getPerson().
Now I am trying to create a form in order to change th user profile.
In there, I would like to create:
$builder->add('degree', 'entity', array(
'class' => 'SciForumVersion2Bundle:Degree',
'property' => 'degree',
));
$builder->add('person.firstname', 'text', array('required'=>true));
$builder->add('person.lastname', 'text', array('required'=>true));
$builder->add('person.address1', 'text', array('label'=>'Address', 'required'=>true));
ETC....
In the twig file, I have to use
<tr>
<td>
{{ form_label(form.degree) }}
</td>
<td>
{{ form_widget(form.degree) }}
</td>
</tr>
<tr>
<td>
{{ form_label(form.firstname) }}
</td>
<td>
{{ form_widget(form.firstname, { 'attr': {'size': 30} }) }}
</td>
</tr>
<tr>
<td>
{{ form_label(form.lastname) }}
</td>
<td>
{{ form_widget(form.lastname, { 'attr': {'size': 30} }) }}
</td>
ETC....
But for the
form.firstname
form.firstname
I am geting the exception:
Method "firstname" for object "Symfony\Component\Form\FormView" does not exist in SciForumVersion2Bundle:User:changeProfile.html.twig at line 54
I managed to resolve this problem. What I did is I created an extra entity called PersonUserEntity. In there, I have all the variables I need:
Then I am using this entity for the form.
Once the form submitted, I am getting information from this entity and populating the Person and the User entity separetly.
After that, I am using: