2

i need to create a form with symfony that has an entity type, so this is im using

->add('assignee', 'entity', array(
           'label' => 'Assignee',
           'class'  => 'PortalBundle:TrnUser',
           'property' => 'username',
           ))

in the generated html it assigns userid as the option value, but i need the username as the option value. something like,

<option value="admin">admin</option>

how can i do this? please help.

thanks..

2 Answers 2

3

You need data transformers. They help you to show data in form as you want. There you can find all information about Data Transformers in Symfony2:

http://symfony.com/doc/current/cookbook/form/data_transformers.html

Sign up to request clarification or add additional context in comments.

Comments

0

You could use the 'choice_value' option with the name of the field you want to use instead of the id.

        $builder
        ->add('user', 'entity', [
            'class' => 'YourBundle\Entity\Locations',
            'property' => 'name',
            'choice_value' => 'name',
            'required' => true,
        ])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.