K
K
Konstantin Zhikhor2019-05-22 11:58:35
symfony
Konstantin Zhikhor, 2019-05-22 11:58:35

Why isn't the form collection showing up?

Hello.
Please tell me why the fields are not displayed?
The bottom line is that there would be dynamic forms.
Company.php

/**
     * @var Collection
     *
     * @ORM\OneToMany(targetEntity="App\Entity\Curator", mappedBy="idcompany", cascade={"persist", "remove"})
     */
    private $curators;

    public function __construct()
    {
        $this->curators = new ArrayCollection();
    }
    /**
     * @return Collection | Curator[]
     */
    public function getCurators(): Collection
    {
        return $this->curators;
    }

    public function addProductField(Curator $curator): self
    {
        if (!$this->curators->contains($curator)) {
            $curator->setIdcompany($this);

            $this->curators[] = $curator;
        }

        return $this;
    }

    public function removeProductField(Curator $curator): self
    {
        if ($this->curators->contains($curator)) {
            $this->curators->removeElement($curator);
        }

        return $this;
    }

curator.php
/**
     * @var Company
     *
     * @ORM\ManyToOne(targetEntity="App\Entity\Company", inversedBy="curators")
     * @ORM\JoinColumn(name="idcompany", referencedColumnName="id", onDelete="CASCADE")
     */
    private $idcompany;

    public function getIdcompany(): ?Company
    {
        return $this->idcompany;
    }

    public function setIdcompany(?Company $idcompany): self
    {
        $this->idcompany = $idcompany;

        return $this;
    }

CompanyController.php
/**
     * @Route("/company/add", name="add_company")
     */
    public function add()
    {
        $company = new Company();



        $form = $this->createForm(CompanyType::class, $company);

        return $this->render('company/add.html.twig', [
            'form' => $form->createView(),
        ]);
    }

CompanyType.php
->add('curators', CollectionType::class, [
                'entry_type' => CuratorType::class,
                'label' => false,
                'by_reference' => false,
                'prototype' => true,
                'allow_add' => true,
                'allow_delete' => true,
            ])

form
<ul>
                {% for curator in form.curators %}
                    <li>{{ form_row(curator.curator_name) }}</li>
                    <li>{{ form_row(curator.email) }}</li>
                {% endfor %}
            </ul>

Information taken from https://symfony.com/doc/current/form/form_collecti... and fkn.ktu10.com/?q=node/10090

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question