How to include some fields from another object in an entity form?

I want to use fields from several objects in one form, can I do this? For example, I want to add in the form surnameof a field ProfileTypeand nameout CountryType. These fields should be a simple string ( text).

How can i do this? Thank!

NOTE. I cannot use entity because Symfony provides only checkboxes, radio buttons and selects for it, however I need to use a simple text box.

+4
source share
1 answer

, . . toMany , One. . : Symfony Forms.

, :

public function buildForm(FormBuilderInterface $builder, array $options)
{
    ...
    $builder->add('profile', new ProfileType());
    $builder->add('country', new CountryType());
    ...
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        ...,
        'cascade_validation' => true,
    ));
}

:

{{ form_widget(form.profile.surname) }}
{{ form_widget(form.country.name) }}

, ProfileType CountryType , , "form_rest (form)" , , , form_rest, symfony , . .

'form_widget (_token)' 'form_rest (form)', . , , . "form_rest (form)" div, "_token", Profile Country. - , .

. , , , , EditThingProfileType EditThingCountryType buildForm() , , .

+5

Source: https://habr.com/ru/post/1533374/


All Articles