Hi
My question:
How to create Symfony 2 Form which allow to manage one-to-many
relation and at the bind time create all necessary "many" Entities and
link them "one" Entity.
My tries:
I have 2 entities: User (id, name, systems) and Systems (id, name,
users)
Inside UserForm (extends Symfony/Components/Form) I have MultiCheckbox
field (I use ChoiceField).
To bind data with object I rewrote doBind (I got example from miam
project):
class UserForm extends Form {
...
protected function doBind(array $data) {
...
$systems = array();
foreach ($data['systems'] as $id) {
$systems[$id] = $em->getRepository('Application
\UserManagementBundle\Entity\System')->find($id);
}
$data['systems'] = $systems;
return parent::doBind($data);
}
}
Unfortunately it doesn't want to work because ChoiceField contains
many CheckBox field and each of them tries to convert data from string
so I got this error:
Expected argument of type string but got object.
at ()
in D:\Development\hosts\miam\src\vendor\Symfony\src\Symfony\Components
\Form\ValueTransformer\BooleanToStringTransformer.php line 37
Ideas which I have and want to try:
1. Create and use new ObjectToStringTransformer
2. Check another examples of symfony 2 applications.
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en