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
define __toString()
in entity class, remove property
option from FormType class:
public function __toString()
{
return $this->firstField . ' - ' . $this->secondField;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.