【发布时间】:2012-03-12 18:25:31
【问题描述】:
要创建一个预约,我需要选择一位患者。 在选择列表中,我需要显示患者的姓名和年龄。
代码:
class AppointmentType extends AbstractType{
public function buildForm(FormBuilder $builder, array $options)
{
$builder->add('id', 'entity', array('class'=>'ProjectAppointmentBundle:Patient',
'label'=>'Patient '
));
}
public function getName()
{
return 'patient';
}
}
和行动:
public function newAction()
{
...
$patient = new Patient();
$entity = new Appointment($patient);
$form = $this->createForm(new AppointmentType(), $entity);
return array(
'entity' => $entity,
'form' => $form->createView()
);
}
这是有效的,但只显示患者姓名(_toString() 方法返回患者姓名)。 我需要在选择字段中显示患者的姓名和年龄。
实体患者有 id、姓名、年龄、地址等...
有人可以帮助我吗?
【问题讨论】:
标签: symfony doctrine-orm