php - Setting a Symfony2 Entity form field using it's id -


i have symfony2 unmapped form has field of type 'entity'. here form type definition:

public function buildform(formbuilderinterface $builder, array $options) {     $builder         ->add('registrationforgotemailtemplate', 'entity', array(             'class' => 'emailbundle:emailtemplate',             'placeholder' => '-- default ---',         )); } 

here build form instance:

$data = array('registrationforgotemailtemplate' => 4); $form = $this->createform($formtype, $data, array(             'action' => $url,             'method' => 'post'             )); 

my problem form not setting registrationforgotemailtemplate field correct entity (id 4). assume because providing id of entity rather instance of it. there way of providing id of entity set field or way pass instance of entity want set field to?

you either use transformer or use "choice" field rather "entity" , inject object provide choices list (likely repository).

personally think you'll find transformer method easier. resulting code nicer


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -