Ver Mensaje Individual
  #7 (permalink)  
Antiguo 31/10/2016, 04:14
AitorLopez
 
Fecha de Ingreso: mayo-2009
Mensajes: 742
Antigüedad: 14 años, 11 meses
Puntos: 6
Respuesta: Valor por defecto en Combo

Al final he conseguido solucionarlo de esta forma:

Código PHP:
Ver original
  1. public function __construct($id) {
  2.     $this->id = $id;
  3.   }
  4.  
  5.     public function buildForm(FormBuilderInterface $builder, array $options)
  6.     {
  7.         $builder
  8.           ->add('subequipos', 'entity', array(
  9.                 'label'                 => 'Nombre del Subequipo',
  10.                 'class'                 => 'IBSEquiposBundle:T_Subequipos',
  11.                 'query_builder'         => function (EntityRepository $er) {
  12.                                            return $er->createQueryBuilder('r');
  13.                 },
  14.                   'choice_attr' => function($choice, $key, $value) {
  15.                     if($value == $this->id)
  16.                     {
  17.                       return ['selected' => 'selected'];
  18.                     }
  19.                     else
  20.                     {
  21.                       return ['value' => $value];
  22.                     }
  23.                   },
  24.                 'choice_label'          => 'getEquiposNombreTuneado'))