Здравствуйте.
Пожалуйста подскажите, почему не выводятся поля ?
Суть в том что бы были динамические формы.
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>
Информацию брал из
https://symfony.com/doc/current/form/form_collecti... и
fkn.ktu10.com/?q=node/10090