0

我有一个 TeamMembers 实体,它有一个规范列表,每个规范都有一个值。

但是我怎样才能获得规格的完整列表,每个规格后面都有一个字段,我可以在其中填写规格值。

该值将与 TeamMember 和 Specification 的 ForeignKey 一起存储在 SpecificationValue 实体中。

所以我想要一个列表:[TeamMember edit_form > Specifications[] > SpecificationValue]

更多信息:

// FORM
class SpecificationValueType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('value')
            ->add('specification')
            ->add('teammember')
        ;
    }

// ENTITY
class SpecificationValue
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="Specifications")
     * @ORM\JoinColumn(name="specification_id", referencedColumnName="id")
     */
    protected $specification; // refernce for specification entity > name, type[ENUM('input','textarea')]

     /**
     * @ORM\ManyToOne(targetEntity="Teammember")
     * @ORM\JoinColumn(name="teammember_id", referencedColumnName="id")
     */
    protected $teammember;

    /**
     * @var string
     * @ORM\Column(name="value", type="string", length=200, nullable=true)
     */
    protected $value;  // value that can be filled in for each 


// ENTITY
class TeamMember
{
    /**
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var string
     * @ORM\Column(name="name", type="string", length=250)
     */
    protected $name; // and some other fields, now skipped for the example

    /**
     * @ORM\OneToMany(targetEntity="SpecificationValue", mappedBy="specifications")
     */
    protected $specifications;

///

 /**
     * Add specificationValue
     *
     * @param \Foobar\MyBundle\Entity\SpecificationValue $specifications
     * @return SpecificationValue
     */
    public function addSpecification(\Foobar\MyBundle\Entity\SpecificationValue $specifications)
    {
        $this->specifications[] = $specifications;

        return $this;
    }

    /**
     * Remove specifications
     *
     * @param \Foobar\MyBundle\Entity\SpecificationValue $specifications
     */
    public function removeSpecification(\Foobar\MyBundle\Entity\SpecificationValue $specifications)
    {
        $this->specifications->removeElement($specifications);
    }

    /**
     * Get specifications
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getSpecifications()
    {
        return $this->specifications;
    }

     /**
     * Get specifications
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getSpecification()
    {
        return $this->specification;
    }
4

1 回答 1

0

您正在寻找的是表单中的实体字段类型,以便能够从您的规范实体集合中进行选择。

  • 向您的 TeamMember 表单类型添加 SpecificationValue 表单类型的集合字段类型(带有 allow_add、原型选项)

团队成员类型

->add('specifications', 'collection', array( 
    'type' => new SpecificationValueType(),
    'allow_add' => true, 
     // ... other options
  ))
  • 添加到您的规范值表单类型中,为规范添加一个“实体”字段,并为相应的值添加一个“值”字段(文本?)。

规格值类型

->add('specification', 'entity', array(
      'class' => 'YourBundle:SpecificationValue',
      'property' => 'name',
      // ... other options
  ))
->add('value')
于 2013-05-27T11:03:30.950 回答