Php 在Symfony表单中添加EntityType的CollectionType

Php 在Symfony表单中添加EntityType的CollectionType,php,symfony,Php,Symfony,我有一个Symfony 4项目,我想在我的表单中创建EntityType的CollectionType,有可能吗 通常我知道如何做一个收集类型,但这个案例很特别 我的安装实体有: /** * @ORM\OneToMany(targetEntity="Option", mappedBy="installation", cascade={"persist"}) * * @Assert\Valid() * * @var ArrayCollection|Option[] */ protect

我有一个Symfony 4项目,我想在我的表单中创建EntityType的CollectionType,有可能吗

通常我知道如何做一个收集类型,但这个案例很特别

我的安装实体有:

/**
 * @ORM\OneToMany(targetEntity="Option", mappedBy="installation", cascade={"persist"})
 *
 * @Assert\Valid()
 *
 * @var ArrayCollection|Option[]
 */
protected $options;
期权实体:

<?php

declare(strict_types = 1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity
 */
class Option
{
   /**
    * @ORM\Id()
    * @ORM\GeneratedValue()
    * @ORM\Column(type="integer", options={"unsigned": true})
    *
    * @var integer|null
    */
    protected $id;

    /**
     * @ORM\Column(type="string", length=255)
     *
     * @Assert\Type(type="string", groups={"etape_installation"})
     * @Assert\Length(max="255", groups={"etape_installation"})
     * @Assert\NotBlank(groups={"etape_installation"})
     *
     * @var string|null
     */
    protected $libelle;

    /**
     * @ORM\Column(type="integer", options={"unsigned": true})
     *
     * @Assert\Type(type="int")
     * @Assert\Range(min="1")
     * @Assert\NotBlank()
     *
     * @var integer|null
     */
    protected $prix;

    /**
     * @ORM\ManyToOne(targetEntity="Installation", inversedBy="options")
     *
     * @Assert\Valid()
     *
     * @var Installation|null
     */
    protected $installation;

    public function getLibelle(): ?string
    {
        return $this->libelle;
    }

    public function setLibelle(?string $libelle): void
    {
        $this->libelle = $libelle;
    }

    public function getPrix(): ?int
    {
        return $this->prix;
    }

    public function setPrix(?int $prix): void
    {
        $this->prix = $prix;
    }

    public function getInstallation(): ?Installation
    {
        return $this->installation;
    }

    public function setInstallation(?Installation $installation): void
    {
        $this->installation = $installation;
    }

    public function __toString(): ?string
    {
        return $this->getLibelle() . ' +' . $this->getPrix() . '€';
    }
}

我被我的选项类型卡住了。。 请问我该怎么办


提前感谢您

我建议您在此处阅读symfony文档:

文档没有教我任何东西,因为我已经知道如何创建表单集合,但是创建EntityType表单集合是不同的。请不要将代码作为截图发布,而是粘贴它们
->add('options', CollectionType::class, [
    'entry_type'    => OptionType::class,
    'entry_options' => [
        'label' => 'Options supplémentaires',
    ],
    'allow_add'     => true,
    'by_reference'  => false,
    'allow_delete'  => true,
    'prototype'     => true,
])