ZF2 annotationbuilder manytoone - >显示选择

时间:2014-07-07 06:56:30

标签: zend-framework annotations zend-framework2

我有2个实体(Text和TextCategory),有很多关系。现在,我使用annotationbuilder为每个实体创建表单,在文本表单中我想显示一个select来选择textcategory。我试过了

  /**
   * @var \Backend\Text\TextCategory
   *
   * @ORM\Column(name="categoryId")
   * @ORM\ManyToOne(targetEntity="Backend\Text\TextCategory", fetch="EAGER")
   * @ORM\JoinColumn(name="categoryId", referencedColumnName="id")
   * @Annotation\Type("DoctrineORMModule\Form\Element\EntitySelect")
   * @Annotation\Options({"label":"Kategorie:", "target_class":"Backend\Entity\TextCategory"})

   */
  private $categoryId;  

但这只显示了一个文本字段。我做错了什么,我错过了什么?

提前致谢!

1 个答案:

答案 0 :(得分:0)

再一次,我发现了问题所在(不知道为什么)。事实证明我必须省略@ORM \ Column ... line:

  /**
   * @var string $categoryId
   * 
   * @ORM\ManyToOne(targetEntity="Backend\Entity\TextCategory", fetch="EAGER")
   * @ORM\JoinColumn(name="categoryId", referencedColumnName="id")
   * @Annotation\Type("DoctrineORMModule\Form\Element\EntitySelect")
   * @Annotation\Required({"required":"true" })
   * @Annotation\Filter({"name":"StripTags"})
   * @Annotation\Options({"label":"Class:",  "property":"name", "target_class" : "Backend\Entity\TextCategory"})
   * @Annotation\Attributes({"value":"0"}) 
   * 
   */
  private $categoryId;   

a突然它起作用了!