title: Symfony 4 Collections form err: Unable to guess
body: <p>I acted according to the documentation <a href="http://symfony.com/doc/current/form/form_collections.html" rel="nofollow noreferrer">http://symfony.com/doc/current/form/form_collections.html</a>, I need to add a common page for editing all records of one entity, and also advised to use the "collection of forms". There were errors like "<code>add use ORM</code>" and similar, now came across a <strong><em><code>ERROR</code></em></strong>. <strong><em><code>Unable to guess how to get a Doctrine instance from the request information for parameter "abilityHolder".</code></em></strong> Google does not say anything, it shows only the old information from symfony2, and I use flex, below I'll attach the files that relate to my task</p>
  
  <p><strong><em>src/Ability.php</em></strong> - my main entity for getting and writing Abilitys</p>
  
  <pre><code>&lt;?php
  
  namespace App\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity(repositoryClass="App\Repository\AbilityRepository")
   * @ORM\Table(name="Ability")
   */
  class Ability
  {
      /**
       * @ORM\Id()
       * @ORM\GeneratedValue()
       * @ORM\Column(type="integer")
       */
      private $id;
  
      /**
       * @ORM\Column(type="integer", name="idItem")
       */
      private $idItem;
  
      /**
       * @ORM\Column(type="string", length=255, nullable=true)
       */
      private $code;
  
      /**
       * @ORM\Column(type="float", name="reloadTime", nullable=true)
       */
      private $reloadTime;
  
      /**
       * @ORM\Column(type="float", name="durationTime", nullable=true)
       */
      private $durationTime;
  
      /**
       * @ORM\Column(type="integer", name="idAbilityType")
       */
      private $idAbilityType;
  
      /**
       * @ORM\Column(type="datetime", nullable=true, name="dateCreated")
       */
      private $dateCreated;
  
      /**
       * @ORM\Column(type="string", length=255, nullable=true)
       */
      private $author;
  
      /**
       * @ORM\Column(type="datetime", nullable=true, name="dateChange")
       */
      private $dateChange;
  
      /**
       * @ORM\Column(type="string", length=255, nullable=true, name="lastAuthor")
       */
      private $lastAuthor;
  
      public function getId()
      {
          return $this-&gt;id;
      }
  
      public function setId(?int $id): self
      {
          $this-&gt;id = $id;
  
          return $this;
      }
  
      public function getIdItem(): ?int
      {
          return $this-&gt;idItem;
      }
  
      public function setIdItem(int $idItem): self
      {
          $this-&gt;idItem = $idItem;
  
          return $this;
      }
  
      public function getCode(): ?string
      {
          return $this-&gt;code;
      }
  
      public function setCode(?string $code): self
      {
          $this-&gt;code = $code;
  
          return $this;
      }
  
      public function getReloadTime(): ?float
      {
          return $this-&gt;reloadTime;
      }
  
      public function setReloadTime(?float $reloadTime): self
      {
          $this-&gt;reloadTime = $reloadTime;
  
          return $this;
      }
  
      public function getDurationTime(): ?float
      {
          return $this-&gt;durationTime;
      }
  
      public function setDurationTime(?float $durationTime): self
      {
          $this-&gt;durationTime = $durationTime;
  
          return $this;
      }
  
      public function getDateCreated(): ?\DateTimeInterface
      {
          return $this-&gt;dateCreated;
      }
  
      public function setDateCreated(\DateTimeInterface $dateCreated): self
      {
          $this-&gt;dateCreated = $dateCreated;
  
          return $this;
      }
  
      public function getAuthor(): ?string
      {
          return $this-&gt;author;
      }
  
      public function setAuthor(string $author): self
      {
          $this-&gt;author = $author;
  
          return $this;
      }
  
      public function getDateChange(): ?\DateTimeInterface
      {
          return $this-&gt;dateChange;
      }
  
      public function setDateChange(\DateTimeInterface $dateChange): self
      {
          $this-&gt;dateChange = $dateChange;
  
          return $this;
      }
  
      public function getLastAuthor(): ?string
      {
          return $this-&gt;lastAuthor;
      }
  
      public function setLastAuthor(string $lastAuthor): self
      {
          $this-&gt;lastAuthor = $lastAuthor;
  
          return $this;
      }
  
      public function getIdAbilityType(): ?int
      {
          return $this-&gt;idAbilityType;
      }
  
      public function setIdAbilityType(int $idAbilityType): self
      {
          $this-&gt;idAbilityType = $idAbilityType;
  
          return $this;
      }
  }
  </code></pre>
  
  <p><strong><em>src/AbilityHolder.php</em></strong> - Collections form entity</p>
  
  <pre><code>&lt;?php
  
  namespace App\Entity;
  
  use Doctrine\Common\Collections\ArrayCollection;
  use Doctrine\ORM\Mapping as ORM;
  
  /**
   * @ORM\Entity
   * @ORM\Table(name="AbilityHolder")
   */
  
  class AbilityHolder
  {
      /**
       * @ORM\Id()
       * @ORM\GeneratedValue()
       * @ORM\Column(type="integer")
       */
      private $id;
  
      protected $abilitys;
  
      public function __construct()
      {
          $this-&gt;abilitys = new ArrayCollection();
      }
  
      public function getAbilitys()
      {
          return $this-&gt;abilitys;
      }
  
      public function getId()
      {
          return $this-&gt;id;
      }
  }
  </code></pre>
  
  <p><strong><em>Form/AbilityType.php</em></strong> form from Ability</p>
  
  <pre><code>&lt;?php
  
  namespace App\Form;
  
  use App\Entity\Ability;
  use App\Entity\Item;
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  use Symfony\Component\Form\Extension\Core\Type\DateType;
  use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  use App\Repository\AbilityTypeRepository;
  use App\Repository\ItemRepository;
  use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  
  class AbilityType extends AbstractType
  {
      protected $abilityTypeRepository;
      protected $itemRepository;
  
      public function __construct(AbilityTypeRepository $abilityTypeRepository, ItemRepository $itemRepository){
          $this-&gt;abilityTypeRepository = $abilityTypeRepository;
          $this-&gt;itemRepository = $itemRepository;
      }
  
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $abilitys = $this-&gt;abilityTypeRepository-&gt;findAll();
          $items = $this-&gt;itemRepository-&gt;findAll();
          foreach ($abilitys as $ability) {
              $abilityCode[] = $ability-&gt;getCode();
              $abilityId[] = $ability-&gt;getId();
          }
          foreach ($items as $item) {
              $itemCode[] = $item-&gt;getCode();
              $itemId[] = $item-&gt;getId();
          }
          $abilityCodeId = array_combine($abilityCode, $abilityId); //склеивание ассоциативного массива из двух массивов
          $itemCodeId = array_combine($itemCode, $itemId); //склеивание ассоциативного массива из двух массивов
          ksort($abilityCodeId);
          ksort($itemCodeId);
  
          $builder
              -&gt;add('idItem', ChoiceType::class, array( 'choices'  =&gt; $itemCodeId ))
              //-&gt;add('idItem', EntityType::class, ['class' =&gt; Item::class,'choice_label' =&gt; 'code','choice_value' =&gt; 'id',])
              -&gt;add('code')
              -&gt;add('reloadTime')
              -&gt;add('durationTime')
              -&gt;add('idAbilityType', ChoiceType::class, array( 'choices'  =&gt; $abilityCodeId ))
              // -&gt;add('dateCreated',DateType::class)
              // -&gt;add('author')
              // -&gt;add('dateChange',DateType::class)
              // -&gt;add('lastAuthor')
          ;
      }
  
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults([
              'data_class' =&gt; Ability::class,
          ]);
      }
  }
  </code></pre>
  
  <p><strong><em>Form/AbilityHolderType.php</em></strong> - form from Ability</p>
  
  <pre><code>&lt;?php
  
  namespace App\Form;
  
  use App\Entity\AbilityHolder;
  use App\Form\AbilityType;
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilderInterface;
  use Symfony\Component\OptionsResolver\OptionsResolver;
  use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  
  class AbilityHolderType extends AbstractType
  {
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
          -&gt;add('abilitys', CollectionType::class, array(
              'entry_type' =&gt; AbilityType::class,
              'entry_options' =&gt; array('label' =&gt; false),
              'allow_add' =&gt; true,
          ))
          ;
      }
  
      public function configureOptions(OptionsResolver $resolver)
      {
          $resolver-&gt;setDefaults([
              'data_class' =&gt; AbilityHolder::class,
          ]);
      }
  }
  </code></pre>
  
  <p><strong><em>Controller/AbilityHolderController.php</em></strong>- form from AbilityHolder-collections form</p>
  
  <pre><code>&lt;?php
  namespace App\Controller;
  
  use App\Entity\AbilityHolder;
  use App\Entity\Ability;
  use App\Form\AbilityHolderType;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\Routing\Annotation\Route;
  use Doctrine\Common\Collections\ArrayCollection;
  use App\Controller\EntityManagerInterface;
  use App\Repository\AbilityRepository;
  use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  
  
  /**
   * @Route("/ability-holder")
   * @ParamConverter (name ="abilityHolder", Class ="App\Entity\AbilityHolder") 
   */
  class AbilityHolderController extends Controller
  {
  
      /**
       * @Route("/edit", name="ability_holder_edit", methods="GET|POST")
       */
      public function edit(Request $request, AbilityHolder $abilityHolder)
      {
          $entityManager = $this-&gt;getDoctrine()-&gt;getManager();
  
          $originalAbilitys = new ArrayCollection();
  
          // Create an ArrayCollection of the current Tag objects in the database
          foreach ($abilityHolder-&gt;getAbilitys() as $ability) {
              $originalAbilitys-&gt;add($ability);
          }
  
          $form = $this-&gt;createForm(AbilityHolderType::class, $abilityHolder);
  
          $form-&gt;handleRequest($request);
  
          if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
              // remove the relationship between the tag and the Task
              foreach ($originalAbilitys as $ability) {
                  if (false === $abilityHolder-&gt;getAbilitys()-&gt;contains($ability)) {
                      // remove the Task from the Tag
                      $tag-&gt;getTasks()-&gt;removeElement($abilityHolder);
  
                      // if it was a many-to-one relationship, remove the relationship like this
                      // $tag-&gt;setTask(null);
  
                      $entityManager-&gt;persist($ability);
  
                      // if you wanted to delete the Tag entirely, you can also do that
                      // $entityManager-&gt;remove($tag);
                  }
              }
  
              $entityManager-&gt;persist($abilityHolder);
              $entityManager-&gt;flush();
              return $this-&gt;redirectToRoute('ability_holder_edit');
          }
          var_dump($abilityHolder);
  
          return $this-&gt;render('ability/edit.holder.html.twig', [
              'form' =&gt; $form-&gt;createView(),
          ]);
      }
  
      /**
       * @Route("/new", name="ability_new", methods="GET|POST")
       */
      /*public function new(Request $request)
      {
          $abilitys = new AbilityHolder();
          $ability1 = new Ability();
          $ability1-&gt;setIdItem('1');
          $ability1-&gt;setCode('code');
          $ability1-&gt;setReloadTime('1');
          $ability1-&gt;setDurationTime('1');
          $ability1-&gt;setIdAbilityType('1');
  
          // dummy code - this is here just so that the Ability has some tags
          // otherwise, this isn't an interesting example
          $abilitys-&gt;getAbilitys()-&gt;add($ability1);
          // end dummy code
  
          $form = $this-&gt;createForm(AbilityHolderType::class, $abilitys);
  
          $form-&gt;handleRequest($request);
  
          if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
              // ... maybe do some form processing, like saving the Ability and Tag objects
          }
  
          return $this-&gt;render('ability/new-holder.html.twig', array(
              'form' =&gt; $form-&gt;createView(),
          ));
      }
  
      /**
       * @Route("/edit", name="ability_edit", methods="GET|POST")
       */
      /*public function edit(Request $request)
  {
      $entityManager = $this-&gt;getDoctrine()-&gt;getManager();
  
      $originalAbilitys = new ArrayCollection();
      $abilityHolder = new AbilityHolder();
  
      // Create an ArrayCollection of the current Tag objects in the database
      foreach ($abilityHolder-&gt;getAbilitys() as $ability) {
          $originalAbilitys-&gt;add($ability);
      }
  
      $editForm = $this-&gt;createForm(AbilityHolderType::class, $abilityHolder);
  
      $editForm-&gt;handleRequest($request);
  
      if ($editForm-&gt;isSubmitted() &amp;&amp; $editForm-&gt;isValid()) {
          // remove the relationship between the ability and the Task
          foreach ($originalAbilitys as $ability) {
              if (false === $abilityHolder-&gt;getAbilitys()-&gt;contains($ability)) {
                  // remove the Task from the Tag
                  $ability-&gt;getAbilitys()-&gt;removeElement($abilityHolder);
  
                  // if it was a many-to-one relationship, remove the relationship like this
                  // $ability-&gt;setTask(null);
  
                  $entityManager-&gt;persist($ability);
  
                  // if you wanted to delete the Tag entirely, you can also do that
                  // $entityManager-&gt;remove($ability);
              }
          }
  
          $entityManager-&gt;persist($abilityHolder);
          $entityManager-&gt;flush();
      }
  
          return $this-&gt;render('ability/new-holder.html.twig', array(
              'form' =&gt; $editForm-&gt;createView(),
          ));
  
      // render some form template
  }*/
  }
  </code></pre>
  
  <p><strong><em>Twig Template</em></strong></p>
  
  <pre><code>{% extends 'base.html.twig' %}
  
  {% block body %}
      {{ form_start(form) }}
  
      {% for ability in form.abilitys %}
          &lt;li&gt;{{ form_row(ability.idItem) }}&lt;/li&gt;
          &lt;li&gt;{{ form_row(ability.code) }}&lt;/li&gt;
          &lt;li&gt;{{ form_row(ability.reloadTime) }}&lt;/li&gt;
          &lt;li&gt;{{ form_row(ability.durationTime) }}&lt;/li&gt;
          &lt;li&gt;{{ form_row(ability.idAbilityType) }}&lt;/li&gt;
      {% endfor %}
  
      {{ form_end(form) }}
  {% endblock %}
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/H7Pnv.jpg" rel="nofollow noreferrer">error</a></p>
  
  <p><strong><em>after adding / {id} to routing</em></strong></p>
  
  <p><a href="https://i.stack.imgur.com/vUg91.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vUg91.jpg" alt="after adding / {id} to routing"></a></p>
  
  <p><strong><em><code>[Semantical Error] The annotation "@Entity" in class App\Entity\AbilityHolder was never imported. Did you maybe forget to add a "use" statement for this annotation?</code></em></strong>
  <a href="https://i.stack.imgur.com/zaieQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zaieQ.jpg" alt="[Semantical Error] The annotation &quot;@Entity&quot; in class App\Entity\AbilityHolder was never imported. Did you maybe forget to add a &quot;use&quot; statement for this annotation?"></a></p>