IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Symfony PHP Discussion :

Symfony "integer instead" error


Sujet :

Symfony PHP

  1. #1
    Membre éclairé
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Janvier 2018
    Messages
    300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2018
    Messages : 300
    Par défaut Symfony "integer instead" error
    Bonjour,
    Nom : value.png
Affichages : 97
Taille : 13,7 Ko
    J'utilise une fonction de mes entités pour insérer un id, mais il semble étonné que je lui propose un entier. Bref, le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
          $absenceJustif->setUtilisateurEtudiant($id);
    l'id passé ici est 8, donc un entier.
    Mon entité Utilisateur:
    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
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
     
    <?php
     
    namespace App\Entity;
     
    use Doctrine\Common\Collections\ArrayCollection;
    use Doctrine\Common\Collections\Collection;
    use Doctrine\ORM\Mapping as ORM;
    use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
    use Symfony\Component\Security\Core\User\UserInterface;
     
    /**
     * @ORM\Entity(repositoryClass="App\Repository\UtilisateurRepository")
     * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
     */
    class Utilisateur implements UserInterface
    {
        /**
         * @ORM\Id()
         * @ORM\GeneratedValue()
         * @ORM\Column(type="integer")
         */
        private $id;
     
        /**
         * @ORM\Column(type="string", length=180, unique=true)
         */
        private $email;
     
        /**
         * @ORM\Column(type="json")
         */
        private $roles = [];
     
        /**
         * @var string The hashed password
         * @ORM\Column(type="string")
         */
        private $password;
     
        /**
         * @ORM\Column(type="string", length=255, nullable=true)
         */
        private $numeroEtudiant;
     
        /**
         * @ORM\Column(type="string", length=255)
         */
        private $prenomUtilisateur;
     
        /**
         * @ORM\Column(type="string", length=255)
         */
        private $nomUtilisateur;
     
        /**
         * @ORM\OneToMany(targetEntity="App\Entity\Pointage", mappedBy="utilisateurEtudiant")
         */
        private $pointage;
     
        /**
         * @ORM\ManyToOne(targetEntity="App\Entity\Formation", inversedBy="utilisateurs")
         */
        private $formation;
     
        /**
         * @ORM\ManyToMany(targetEntity="App\Entity\Cours", inversedBy="utilisateurs")
         */
        private $cours;
     
        public function __construct()
        {
            $this->pointage = new ArrayCollection();
            $this->cours = new ArrayCollection();
        }
     
        public function getId(): ?int
        {
            return $this->id;
        }
     
        public function getEmail(): ?string
        {
            return $this->email;
        }
     
        public function setEmail(string $email): self
        {
            $this->email = $email;
     
            return $this;
        }
     
        /**
         * A visual identifier that represents this user.
         *
         * @see UserInterface
         */
        public function getUsername(): string
        {
            return (string) $this->numeroEtudiant;
        }
     
        /**
         * @see UserInterface
         */
        public function getRoles(): array
        {
            $roles = $this->roles;
            // guarantee every user at least has ROLE_USER
            $roles[] = 'ROLE_USER';
     
            return array_unique($roles, SORT_REGULAR);
        }
     
        public function setRoles(array $roles): self
        {
            $this->roles = $roles;
     
            return $this;
        }
     
        /**
         * @see UserInterface
         */
        public function getPassword(): string
        {
            return (string) $this->password;
        }
     
        public function setPassword(string $password): self
        {
            $this->password = $password;
     
            return $this;
        }
     
        /**
         * @see UserInterface
         */
        public function getSalt()
        {
            // not needed when using the "bcrypt" algorithm in security.yaml
        }
     
        /**
         * @see UserInterface
         */
        public function eraseCredentials()
        {
            // If you store any temporary, sensitive data on the user, clear it here
            // $this->plainPassword = null;
        }
     
        public function getNumeroEtudiant(): ?string
        {
            return $this->numeroEtudiant;
        }
     
        public function setNumeroEtudiant(?string $numeroEtudiant): self
        {
            $this->numeroEtudiant = $numeroEtudiant;
     
            return $this;
        }
     
        public function getPrenomUtilisateur(): ?string
        {
            return $this->prenomUtilisateur;
        }
     
        public function setPrenomUtilisateur(string $prenomUtilisateur): self
        {
            $this->prenomUtilisateur = $prenomUtilisateur;
     
            return $this;
        }
     
        public function getNomUtilisateur(): ?string
        {
            return $this->nomUtilisateur;
        }
     
        public function setNomUtilisateur(string $nomUtilisateur): self
        {
            $this->nomUtilisateur = $nomUtilisateur;
     
            return $this;
        }
     
        /**
         * @return Collection|Pointage[]
         */
        public function getPointage(): Collection
        {
            return $this->pointage;
        }
     
        public function addPointage(Pointage $pointage): self
        {
            if (!$this->pointage->contains($pointage)) {
                $this->pointage[] = $pointage;
                $pointage->setUtilisateurEtudiant($this);
            }
     
            return $this;
        }
     
        public function removePointage(Pointage $pointage): self
        {
            if ($this->pointage->contains($pointage)) {
                $this->pointage->removeElement($pointage);
                // set the owning side to null (unless already changed)
                if ($pointage->getUtilisateurEtudiant() === $this) {
                    $pointage->setUtilisateurEtudiant(null);
                }
            }
     
            return $this;
        }
     
        public function getFormation(): ?Formation
        {
            return $this->formation;
        }
     
        public function setFormation(?Formation $formation): self
        {
            $this->formation = $formation;
     
            return $this;
        }
     
        /**
         * @return Collection|Cours[]
         */
        public function getCours(): Collection
        {
            return $this->cours;
        }
     
        public function addCour(Cours $cour): self
        {
            if (!$this->cours->contains($cour)) {
                $this->cours[] = $cour;
            }
     
            return $this;
        }
     
        public function removeCour(Cours $cour): self
        {
            if ($this->cours->contains($cour)) {
                $this->cours->removeElement($cour);
            }
     
            return $this;
        }
     
    	public function __toString()
    	{
     
    		$nom = $this->getNomUtilisateur();
    		$prenom = $this->getPrenomUtilisateur();
     
    		$identite = $prenom." ".$nom;
    		return $identite;
        }
     
    	public function __toString2()
    	{
    		return $this->getUsername();
        }
    }
    Mon entité AbsencesJustifications :
    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
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
     
    <?php
     
    namespace App\Entity;
     
    use Doctrine\ORM\Mapping as ORM;
     
    /**
     * @ORM\Entity(repositoryClass="App\Repository\AbsencesJustificationsRepository")
     */
    class AbsencesJustifications
    {
        /**
         * @ORM\Id()
         * @ORM\GeneratedValue()
         * @ORM\Column(type="integer")
         */
        private $id;
     
        /**
         * @ORM\Column(type="string", length=255)
         */
        private $cours;
     
        /**
         * @ORM\Column(type="string", length=255)
         */
        private $plageHoraireJustifAbsence;
     
        /**
         * @ORM\ManyToOne(targetEntity="App\Entity\Utilisateur")
         * @ORM\JoinColumn(name="utilisateur_etudiant", referencedColumnName="id")
         */
        private $utilisateurEtudiant;
     
        /**
         * @ORM\ManyToOne(targetEntity="App\Entity\Formation")
         * @ORM\JoinColumn(name="formation", referencedColumnName="id")
         */
        private $formation;
        /**
         * @ORM\Column(type="string", length=255)
         */
        private $dateCours;
     
        /**
         * @ORM\Column(type="string", length=255)
         */
        private $lienFichier;
            /**
         * @ORM\Column(type="string", length=255)
         */
        private $date;
            /**
         * @ORM\Column(type="integer")
         */
        private $valider;
     
        public function getId(): ?int
        {
            return $this->id;
        }
     
        public function getCours(): ?string
        {
            return $this->cours;
        }
     
        public function setCours(string $cours): self
        {
            $this->cours = $cours;
     
            return $this;
        }
        public function getPlageHoraire(): ?string
        {
            return $this->plageHoraireJustifAbsence;
        }
     
        public function setPlageHoraire(string $plageHoraireJustifAbsence): self
        {
            $this->plageHoraire = $plageHoraireJustifAbsence;
     
            return $this;
        }
        public function getPlageHoraireJustifAbsence(): ?string
        {
            return $this->plageHoraireJustifAbsence;
        }
     
        public function setPlageHoraireJustifAbsence(string $plageHoraireJustifAbsence): self
        {
            $this->plageHoraireJustifAbsence = $plageHoraireJustifAbsence;
     
            return $this;
        }
     
        public function getUtilisateurEtudiant(): ?int
        {
            return $this->utilisateurEtudiant;
        }
     
        public function setUtilisateurEtudiant(int $utilisateurEtudiant): self
        {
            $this->utilisateurEtudiant = $utilisateurEtudiant;
     
            return $this;
        }
     
        public function getFormation(): ?string
        {
            return $this->formation;
        }
     
        public function setFormation(string $formation): self
        {
            $this->formation = $formation;
     
            return $this;
        }
     
        public function getLienFichier(): ?string
        {
            return $this->lienFichier;
        }
     
        public function setLienFichier(string $lienFichier): self
        {
            $this->lienFichier = $lienFichier;
     
            return $this;
        }
        public function getDate(): ?string
        {
            return $this->date;
        }
     
        public function setDate()
        {
            $date = new \DateTime("now");
            $this->date = date_format($date, 'Y-m-d H:i:s');
            //$this->date = new \DateTime("now");
        }
        public function getDateCours(): ?string
        {
            return $this->dateCours;
        }
     
        public function setDateCours(string $dateCours): self
        {
            $this->dateCours = $dateCours;
     
            return $this;
        }
        public function getValider(): ?int
        {
            return $this->valider;
        }
        public function setValider(int $valider): self
        {
            $this->valider = $valider;
     
            return $this;
        }
        public function getIdCoursEmarge(): ?int
        {
            return $this->idCoursEmarge;
        }
        public function setIdCoursEmarge(int $idCoursEmarge): self
        {
            $this->idCoursEmarge = $idCoursEmarge;
     
            return $this;
        }
    }
    J'ai bien définis que j'attendais un entier... côté base de données pas de soucis, il attends un entier aussi. Le problème doit être simple mais je ne pige pas.
    Merci d'avance

  2. #2
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    Salut,

    Ici utilisateurEtudiant est une relation vers l’entité Utilisateur et attends donc un objet Utilisateur qui sera converti et inséré dans les différentes tables lors du flush. Pourquoi insérer un entier? La méthode est de récupérer votre utilisateur avec l'entityManager et de le passer à la méthode. D'ailleurs changer la signature en Utilisateur et pas int

  3. #3
    Membre éclairé
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Janvier 2018
    Messages
    300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2018
    Messages : 300
    Par défaut
    Merci pour ta réponse!
    En effet cette relation est tout à fait voulu.
    j'ai besoin d'inserer un entier dzns "AbsenceJustif" car je créé des justificatifs liés à un nom d'étudiant. J'ai donc besoin de creer la justification en utilisant l'id de User.
    Comment devrais-je faire dans ce cas? merci!

  4. #4
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    https://symfony.com/doc/current/doct...lated-entities dans la méthode addPointage
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
        public function addPointage(Pointage $pointage): self
        {
            if (!$this->pointage->contains($pointage)) {
                $this->pointage[] = $pointage;
                $pointage->setUtilisateurEtudiant($this);
            }
     
            return $this;
        }
    Plusieurs solutions dans addPointage tu ajoutes un nouveau pointage avec l'utilisateur actuel tu peux faire un pour vérifier. Le problème vient du type de la fonction setUtilisateurEtudiant qui doit être un Utilisateur et pas un entier n'oublie pas le namespace de l'entité
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
       public function setUtilisateurEtudiant(Utilisateur $utilisateurEtudiant): self
        {
            $this->utilisateurEtudiant = $utilisateurEtudiant;
     
            return $this;
        }

  5. #5
    Membre éclairé
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Janvier 2018
    Messages
    300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2018
    Messages : 300
    Par défaut
    Merci pour ta réponse!
    Je suis désolé, je ne dois pas être très doué, mais je n'y parviens pas. En m'appuyant sur la doc et ton code fournit, j'ai une nouvelle erreur:
    Nom : pooooo.png
Affichages : 76
Taille : 42,2 Ko
    On peut voir sur ce screen qu'il récupère bien l'entier que je lui envois (8). Avant j'insérais une simple chaîne de caractère et je n'avais pas de soucis, seulement maintenant que je préfère travailler avec des id (pour avoir une bdd + cohérente), je galère un peu...
    Merci d'avance :S

  6. #6
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    Curieux dans le setter c'est bien un objet utilisateur que tu passes? peux tu faire un dd et vérifier si ça n'a me marche pas fait un new Utilisateur en paramètre pour tester. Pour la cohérence des données justement ici c'est lorm qui s'en occupe donc pas de soucis de mauvaise manipulation tu manipules juste des objets.

  7. #7
    Membre éclairé
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Janvier 2018
    Messages
    300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2018
    Messages : 300
    Par défaut
    Merci pour ton retour.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
        public function getId(): ?int
        {
            dd($this->id);
            return $this->id;
        }
    Ceci me renvoie bien "8", soit la valeur que je passe ici :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    $id = $user->getId();
    $absenceJustif->setUtilisateurEtudiant($id);
    Je te remets mes 2 entités au complet:
    AbsencesJustifications.php
    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
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
     
    <?php
     
    namespace App\Entity;
     
    use Doctrine\ORM\Mapping as ORM;
     
    /**
     * @ORM\Entity(repositoryClass="App\Repository\AbsencesJustificationsRepository")
     */
    class AbsencesJustifications
    {
        /**
         * @ORM\Id()
         * @ORM\GeneratedValue()
         * @ORM\Column(type="integer")
         */
        private $id;
     
        /**
         * @ORM\Column(type="string", length=255)
         */
        private $cours;
     
        /**
         * @ORM\Column(type="string", length=255)
         */
        private $plageHoraireJustifAbsence;
     
        /**
         * @ORM\ManyToOne(targetEntity="App\Entity\Utilisateur")
         */
        private $utilisateurEtudiant;
     
        /**
         * @ORM\ManyToOne(targetEntity="App\Entity\Formation")
         * @ORM\JoinColumn(name="formation", referencedColumnName="id")
         */
        private $formation;
        /**
         * @ORM\Column(type="string", length=255)
         */
        private $dateCours;
     
        /**
         * @ORM\Column(type="string", length=255)
         */
        private $lienFichier;
            /**
         * @ORM\Column(type="string", length=255)
         */
        private $date;
            /**
         * @ORM\Column(type="integer")
         */
        private $valider;
     
        public function getId(): ?int
        {
            return $this->id;
        }
     
        public function getCours(): ?string
        {
            return $this->cours;
        }
     
        public function setCours(string $cours): self
        {
            $this->cours = $cours;
     
            return $this;
        }
        public function getPlageHoraire(): ?string
        {
            return $this->plageHoraireJustifAbsence;
        }
     
        public function setPlageHoraire(string $plageHoraireJustifAbsence): self
        {
            $this->plageHoraire = $plageHoraireJustifAbsence;
     
            return $this;
        }
        public function getPlageHoraireJustifAbsence(): ?string
        {
            return $this->plageHoraireJustifAbsence;
        }
     
        public function setPlageHoraireJustifAbsence(string $plageHoraireJustifAbsence): self
        {
            $this->plageHoraireJustifAbsence = $plageHoraireJustifAbsence;
     
            return $this;
        }
     
        public function getUtilisateurEtudiant(): ?Utilisateur
        {
            return $this->utilisateurEtudiant;
        }
     
        public function setUtilisateurEtudiant(?Utilisateur $utilisateurEtudiant): self
        {
            $this->utilisateurEtudiant = $utilisateurEtudiant;
     
            return $this;
        }
        public function getFormation(): ?string
        {
            return $this->formation;
        }
     
        public function setFormation(string $formation): self
        {
            $this->formation = $formation;
     
            return $this;
        }
     
        public function getLienFichier(): ?string
        {
            return $this->lienFichier;
        }
     
        public function setLienFichier(string $lienFichier): self
        {
            $this->lienFichier = $lienFichier;
     
            return $this;
        }
        public function getDate(): ?string
        {
            return $this->date;
        }
     
        public function setDate()
        {
            $date = new \DateTime("now");
            $this->date = date_format($date, 'Y-m-d H:i:s');
            //$this->date = new \DateTime("now");
        }
        public function getDateCours(): ?string
        {
            return $this->dateCours;
        }
     
        public function setDateCours(string $dateCours): self
        {
            $this->dateCours = $dateCours;
     
            return $this;
        }
        public function getValider(): ?int
        {
            return $this->valider;
        }
        public function setValider(int $valider): self
        {
            $this->valider = $valider;
     
            return $this;
        }
        public function getIdCoursEmarge(): ?int
        {
            return $this->idCoursEmarge;
        }
        public function setIdCoursEmarge(int $idCoursEmarge): self
        {
            $this->idCoursEmarge = $idCoursEmarge;
     
            return $this;
        }
    }
    Utilisateur.php
    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
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
     
    <?php
     
    namespace App\Entity;
     
    use Doctrine\Common\Collections\ArrayCollection;
    use Doctrine\Common\Collections\Collection;
    use Doctrine\ORM\Mapping as ORM;
    use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
    use Symfony\Component\Security\Core\User\UserInterface;
     
    /**
     * @ORM\Entity(repositoryClass="App\Repository\UtilisateurRepository")
     * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
     */
    class Utilisateur implements UserInterface
    {
        /**
         * @ORM\Id()
         * @ORM\GeneratedValue()
         * @ORM\Column(type="integer")
         */
        private $id;
     
        /**
         * @ORM\Column(type="string", length=180, unique=true)
         */
        private $email;
     
        /**
         * @ORM\Column(type="json")
         */
        private $roles = [];
     
        /**
         * @var string The hashed password
         * @ORM\Column(type="string")
         */
        private $password;
     
        /**
         * @ORM\Column(type="string", length=255, nullable=true)
         */
        private $numeroEtudiant;
     
        /**
         * @ORM\Column(type="string", length=255)
         */
        private $prenomUtilisateur;
     
        /**
         * @ORM\Column(type="string", length=255)
         */
        private $nomUtilisateur;
     
        /**
         * @ORM\OneToMany(targetEntity="App\Entity\Pointage", mappedBy="utilisateurEtudiant")
         */
        private $pointage;
     
        /**
         * @ORM\ManyToOne(targetEntity="App\Entity\Formation", inversedBy="utilisateurs")
         */
        private $formation;
     
        /**
         * @ORM\ManyToMany(targetEntity="App\Entity\Cours", inversedBy="utilisateurs")
         */
        private $cours;
     
        public function __construct()
        {
            $this->pointage = new ArrayCollection();
            $this->cours = new ArrayCollection();
        }
     
        public function getId(): ?int
        {
            return $this->id;
        }
     
        public function getEmail(): ?string
        {
            return $this->email;
        }
     
        public function setEmail(string $email): self
        {
            $this->email = $email;
     
            return $this;
        }
     
        /**
         * A visual identifier that represents this user.
         *
         * @see UserInterface
         */
        public function getUsername(): string
        {
            return (string) $this->numeroEtudiant;
        }
     
        /**
         * @see UserInterface
         */
        public function getRoles(): array
        {
            $roles = $this->roles;
            // guarantee every user at least has ROLE_USER
            $roles[] = 'ROLE_USER';
     
            return array_unique($roles, SORT_REGULAR);
        }
     
        public function setRoles(array $roles): self
        {
            $this->roles = $roles;
     
            return $this;
        }
     
        /**
         * @see UserInterface
         */
        public function getPassword(): string
        {
            return (string) $this->password;
        }
     
        public function setPassword(string $password): self
        {
            $this->password = $password;
     
            return $this;
        }
     
        /**
         * @see UserInterface
         */
        public function getSalt()
        {
            // not needed when using the "bcrypt" algorithm in security.yaml
        }
     
        /**
         * @see UserInterface
         */
        public function eraseCredentials()
        {
            // If you store any temporary, sensitive data on the user, clear it here
            // $this->plainPassword = null;
        }
     
        public function getNumeroEtudiant(): ?string
        {
            return $this->numeroEtudiant;
        }
     
        public function setNumeroEtudiant(?string $numeroEtudiant): self
        {
            $this->numeroEtudiant = $numeroEtudiant;
     
            return $this;
        }
     
        public function getPrenomUtilisateur(): ?string
        {
            return $this->prenomUtilisateur;
        }
     
        public function setPrenomUtilisateur(string $prenomUtilisateur): self
        {
            $this->prenomUtilisateur = $prenomUtilisateur;
     
            return $this;
        }
     
        public function getNomUtilisateur(): ?string
        {
            return $this->nomUtilisateur;
        }
     
        public function setNomUtilisateur(string $nomUtilisateur): self
        {
            $this->nomUtilisateur = $nomUtilisateur;
     
            return $this;
        }
     
        /**
         * @return Collection|Pointage[]
         */
        public function getPointage(): Collection
        {
            return $this->pointage;
        }
     
        public function addPointage(Pointage $pointage): self
        {
            if (!$this->pointage->contains($pointage)) {
                $this->pointage[] = $pointage;
                $pointage->setUtilisateurEtudiant($this);
                dd($this, $pointage);
            }
     
            return $this;
        }
     
        public function removePointage(Pointage $pointage): self
        {
            if ($this->pointage->contains($pointage)) {
                $this->pointage->removeElement($pointage);
                // set the owning side to null (unless already changed)
                if ($pointage->getUtilisateurEtudiant() === $this) {
                    $pointage->setUtilisateurEtudiant(null);
                }
            }
     
            return $this;
        }
     
        public function getFormation(): ?Formation
        {
            return $this->formation;
        }
     
        public function setFormation(?Formation $formation): self
        {
            $this->formation = $formation;
     
            return $this;
        }
     
        /**
         * @return Collection|Cours[]
         */
        public function getCours(): Collection
        {
            return $this->cours;
        }
     
        public function addCour(Cours $cour): self
        {
            if (!$this->cours->contains($cour)) {
                $this->cours[] = $cour;
            }
     
            return $this;
        }
     
        public function removeCour(Cours $cour): self
        {
            if ($this->cours->contains($cour)) {
                $this->cours->removeElement($cour);
            }
     
            return $this;
        }
     
    	public function __toString()
    	{
     
    		$nom = $this->getNomUtilisateur();
    		$prenom = $this->getPrenomUtilisateur();
     
    		$identite = $prenom." ".$nom;
    		return $identite;
        }
     
    	public function __toString2()
    	{
    		return $this->getUsername();
        }
    }
    Je continue de farfouiller de mon côté... si tu as une idée je suis preneur! Ca serait top =D merci

  8. #8
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    Je comprends mieux au lieu de

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $id = $user->getId();
    $absenceJustif->setUtilisateurEtudiant($id);
    fait

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $absenceJustif->setUtilisateurEtudiant($user);

  9. #9
    Membre éclairé
    Homme Profil pro
    Assistant aux utilisateurs
    Inscrit en
    Janvier 2018
    Messages
    300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Assistant aux utilisateurs
    Secteur : Distribution

    Informations forums :
    Inscription : Janvier 2018
    Messages : 300
    Par défaut
    C'est tout à fait ça, je comprends mieux mon erreur.
    Merci beaucoup, sujet résolu!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Symfony erreur 500 Internal Server Error - FileLoaderLoadException
    Par Francisco22 dans le forum Bibliothèques et frameworks
    Réponses: 0
    Dernier message: 11/08/2013, 22h09
  2. Réponses: 16
    Dernier message: 28/06/2007, 17h10
  3. [VB6>VB.NET] Comment coder "break on all errors"
    Par RiiiDD dans le forum VB.NET
    Réponses: 5
    Dernier message: 07/03/2006, 12h53
  4. Réponses: 6
    Dernier message: 21/10/2005, 18h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo