Bonjour,

J'ai un peu cherché à gauche à droite mais je ne comprends toujours pas ce qui m'arrive. Je suis en PHP8.0. J'essaye d'attribuer un Id de projet à un contact et j'ai une erreur que je n'arrive pas à résoudre :

App\Entity\Visa\VisaContacts::setIdProjet(): Argument #1 ($idProjet) must be of type ?App\Entity\Visa\VisaProjets, int given, called in C:\Users\lenovo\Documents\NetBeansProjects\syntherm-NEW\src\Controller\Visa\VisaController.php on line 153
Le code de mon entité est le suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
 
namespace App\Entity\Visa;
 
use App\Entity\User\User;
use App\Repository\Visa\VisaContactsRepository;
use Doctrine\ORM\Mapping as ORM;
 
/**
 * @ORM\Entity(repositoryClass=VisaContactsRepository::class)
 */
class VisaContacts
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;
 
    /**
     * @ORM\ManyToOne(targetEntity=VisaProjets::class)
     */
    private $idProjet;
 
 
    /**
     * @ORM\ManyToOne(targetEntity=User::class)
     */
    private $idUser;
 
    public function getId(): ?int
    {
        return $this->id;
    }
 
    public function getIdProjet(): ?VisaProjets
    {
        return $this->idProjet;
    }
 
    public function setIdProjet(?VisaProjets $idProjet): self
    {
        $this->idProjet = $idProjet;
 
        return $this;
    }
 
    public function getIdUser(): ?User
    {
        return $this->idUser;
    }
 
    public function setIdUser(?User $idUser): self
    {
        $this->idUser = $idUser;
 
        return $this;
    }
}
Avec pour controller :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    /**
     * @Route("/visa/nouveauContact/{idProjet}", name="visa_nouveau_contact", options={"expose" : true})
     */
    public function visa_nouveau_contact(EntityManagerInterface $em, Request $req, Session $session, Security $security, $idProjet)
    {
        //'Démarrage de session'
        $session->start();
        $session->set("lastPage", "visa_nouveau_contact");
        $this->em = $em;
        $this->user = $security->getUser();
 
        //création d'un nouvel object
        $nouveau_contact = new \App\Entity\Visa\VisaContacts();
        $form = $this->createForm(\App\Form\Visa\VisaContactsType::class, $nouveau_contact);
        $form->handleRequest($req);
 
        //Action si envoyé
        if ($form->isSubmitted() && $form->isValid()) {
 
            //ajout du compte user
            if ($this->user != null) {
                $nouveau_contact->setIdUser($this->user);
            }
            //ajout de l'ID du projet ???
            dump($idProjet);
            $nouveau_contact->setIdProjet($idProjet);
 
            $em->persist($nouveau_contact);
            $em->flush();
        }
 
        return $this->render('visa/visa_nouveau_contact.html.twig', [
            'form' => $form->createView()
        ]);
    }
Avez vous une idée ?

Salutations,

Thomas.