dongwen3437
2018-07-25 15:41
浏览 29
已采纳

Symfony2.3来自查询的选择字段的设置值和innerHTML

From a query I'm trying to personalize the choice field.

this is how I get the content of the select:

    $em = $this->getDoctrine()->getManager();
    $query2 = $em->createQuery("SELECT p.id,p.nombre FROM Exppromociones p");
    $productos = $query2->getArrayResult();

The table should look like this:

{"id":93,"nombre":"Bucket"},
{"id":152,"nombre":"Spoon"},
{"id":142,"nombre":"Fork"}

With the variable $productos I build a form:

   $form = $this->createFormBuilder()
        ->add('productos', 'choice', array('label' => 'Productos',
            'required' => true,
            'choices' => $productos,
        ))
        ->getForm();

And that form results to:

<optgroup label="0">
   <option value="id">93</option>
   <option value="nombre">Espumante Chandon Brut Nature</option>
</optgroup>

I want the choices field to have the value equal to the id and the innerHTML equal to nombre, like this:

<option value=93>Bucket</option>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题