Error creating a combobox powered from Symfony doctrine

1

Now create the combobox, it is displayed correctly and it contains the correct value, but at the time of saving, it is entered in 0 in the database.

My code is as follows

->add('idBpCustomer', 'entity', array(
'class' => 'chriscrudBundle:BpCrpCustomer',
'property' => 'name',
'query_builder' => function (EntityRepository $er){
    return $er->createQueryBuilder('c')
        ->orderBy('c.name','ASC')
        ;
},))

In the BpCrpCustomer entity

public function __toString(){
    return $this->getName();
}

What do I need?

    
asked by Chriz CR 18.03.2017 в 23:15
source

1 answer

1

In the controller I make my query and command in sight and on the view I make a for to paint the select

Controller:

   public function indexAction()
{
    $em = $this->getDoctrine()->getManager();

    $bpCrpCards = $em->getRepository('AppBundle:BpCrpCard');

    $query = $bpCrpCards->createQueryBuilder('c')
    ->select('c.idCard,  p.nombres,p.apellidos')
    ->innerJoin('AppBundle:User', 'p' , 'WITH' , 'p.id = c.idUsuario')
    ->where('c.idUsuario = :idUsuario AND c.status = :status')
    ->setParameter('idUsuario', $this->getUser()->getId())
    ->setParameter('status', 1)
    ->getQuery();
    $bpCrpCards = $query->getResult();

    return $this->render('AppBundle:bpcrpcard:index.html.twig', array(
        'bpCrpCards' => $bpCrpCards,
    ));
}

Vista html.twig

<select class="form-control select" id="bp_card" name="bp_card" required="true" style="width: 100%;">
                    <option disabled="true" value selected>Seleccione...</option>
                    {% for bpCrpCards in bpCrpCards  %}
                        <option value="{{bpCrpCards.idBpToken}}">{{bpCrpCards}}</option>          
                    {%endfor%}
                </select>
    
answered by 05.10.2017 / 20:33
source