title: Symfony 5 - Object of class App\Entity\Vegetal could not be converted to string
body: <p>I have a problem when trying to add an image to a folder on a website that I'm developping currently. When I try to rename the file, I would like it to be : idOfMyObject.jpg</p>
  <p>But when I want to add it on my form, this error code pops up : &quot;Object of class App\Entity\Vegetal could not be converted to string&quot;.</p>
  <p>The problem's apparently inside the isset, but I can't find a solution to convert my id to string.</p>
  <p>Here is the Controller :</p>
  <pre><code>public function ajouterVegetal(Request $request): Response
      {   
          $fFeuille = new FormeFeuille();
      
          $vegetal = new Vegetal();
          $formVegetal = $this-&gt;createForm(VegetalType::class, $vegetal);
          $formVegetal-&gt;handleRequest($request);
  
          //Si le formulaire est bien valide (tous les champs remplis) et que le bouton submit est appuyé
          if ($formVegetal-&gt;isSubmitted() &amp;&amp; $formVegetal-&gt;isValid()) { 
              //on récupère les données du formaulaire
              $vegetal = $formVegetal-&gt;getData();
              $entityManager = $this-&gt;getDoctrine()-&gt;getManager();
              
              //on récupère les données de la variable image dans le formulaire d'ajout     
              $fileDownload = $formVegetal['images']-&gt;getData();
              //si le fichier existe, on le renomme avec l'id du végétal, pour le sauvegarder dans le dossier configuré dans service.yaml
              if (isset($fileDownload))
              {
                  $nomImage = $fFeuille-&gt;getVegetals()-&gt;{$this-&gt;$vegetal-&gt;getId()}.'.'.$fileDownload-&gt;guessExtension();         
                  $fileDownload-&gt;move(
                       $this-&gt;getParameter('upload_directory'),
                       $nomImage
                  );
              }
              //on ajoute les données dans la base
              $entityManager-&gt;persist($vegetal);
              $entityManager-&gt;flush();
  
              $this-&gt;getDoctrine()-&gt;getManager()-&gt;flush();      
  
              return $this-&gt;redirectToRoute('listerVegetal');
          } else {
              return $this-&gt;render('Vegetal/ajouterVegetal.html.twig', [
                  'vegetal' =&gt; $vegetal,
                  'form' =&gt; $formVegetal-&gt;createView(),
              ]);
          }
      }
  </code></pre>