Home:ALL Converter>Using two entities to create a form

Using two entities to create a form

Ask Time:2014-08-07T18:52:14         Author:khernik

Json Formatter

I use one general form type class to create all forms in my application. From controllers I only pass some parameters to it so that it knows which fields to render. For example:

$form = $this->createForm(new CommonType($repository, $queryResultSet), new UsersEntity(),
        [
            'action'          => $this->generateUrl('user_edit'),
            'attr'            => ['class' => 'stdform'],
            'repository_name' => 'AcmeBundle:Users'
        ]);

And then CommonType class generates fields based on arrays from repository class.


However I need to add two entities now - the form has to contain fields from user and shop repositories/entities.

I thought about creating two forms here and connecting them, but I wouldn't be able to persist it to the database later.

How can I solve this problem?

I can't use form embedding because I have CommonType class here in my case.

Author:khernik,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/25180612/using-two-entities-to-create-a-form
yy