1

In my table I have users and their full name is split into two fields: first_name and last_name. When displaying these users in a form it is only showing the persons first_name. How can I have both the first_name and the last_name in the select option, is this possible? Here is my current code, not sure where to go from here. Thanks.

$builder->add('buyer','entity',array(
        'required' => false,
        'class' => 'WICUserBundle:User',
        'label' => 'User',
        'property' => 'first_name', // <== how do I add the last_name here as well
        'query_builder' => function(EntityRepository $er){
                return $er->createQueryBuilder('u')
                    ->where('u.account=?0')
                    ->setParameters(array(
                        $this->account
                    ));
            },
        'empty_value' => 'Select User',
    ));

Found the Answer Here: Symfony 2 Create a entity form field with 2 properties

Community
  • 1
  • 1
LargeTuna
  • 2,694
  • 7
  • 46
  • 92

1 Answers1

2

define __toString() in entity class, remove property option from FormType class:

public function __toString()
{
    return $this->firstField . ' - ' . $this->secondField;
}
xurshid29
  • 4,172
  • 1
  • 20
  • 25