Bonjour,

Ce que je fais

Créer une entité User.php et Employe.php

//user entity

<?php

namespace RH\GRHBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use RH\GRHBundle\Entity\Employe;
use Symfony\Component\Validator\Constraints as Assert;
/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

     public function __construct()
    {
        parent::__construct();
        // your own logic
    }

    public function __toString(){
        // to show the name  selected
       return ($this->username);
        // to show the id  selected
        //return $this->id;
    }

}

//employe entity

<?php

namespace RH\GRHBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use RH\GRHBundle\Entity\User;
use Symfony\Component\Validator\Constraints as Assert;
/**
 * Employe
 *
 * @ORM\Table(name="employe")
 * @ORM\Entity(repositoryClass="RH\GRHBundle\Repository\EmployeRepository")
 */
class Employe
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="nom", type="string", length=255)
     */
    private $nom;

    /**
     * @var string
     *
     * @ORM\Column(name="prenom", type="string", length=255)
     */
    private $prenom;

    /**
     * @var int
     *
     * @ORM\Column(name="cin", type="bigint")
     */
    private $cin;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="date_naissance", type="date")
     */
    private $dateNaissance;

    /**
     * @var string
     *
     * @ORM\Column(name="adresse", type="string", length=255)
     */
    private $adresse;

    /**
     * @var string
     *
     * @ORM\Column(name="sexe", type="string", length=255)
     */
    private $sexe;

    /**
     * @var string
     *
     * @ORM\Column(name="etatcivil", type="string", length=255)
     */
    private $etatcivil;

    /**
     * @var int
     *
     * @ORM\Column(name="telephone", type="bigint")
     */
    private $telephone;

    /**
     * @var string
     *
     * @ORM\Column(name="ville", type="string", length=255)
     */
    private $ville;

    /**
     * @var string
     *
     * @ORM\Column(name="province", type="string", length=255)
     */
    private $province;

    /**
     * @var int
     *
     * @ORM\Column(name="codepostal", type="bigint")
     */
    private $codepostal;

    /**
     * @var string
     *
     * @ORM\Column(name="image", type="string", length=255)
     */
    private $image;

    /**
     * @var string
     *
     * @ORM\Column(name="diplome", type="string", length=255)
     */
    private $diplome;

    /**
     * @var string
     *
     * @ORM\Column(name="experience", type="string", length=255)
     */
    private $experience;

    /**
     * @var string
     *
     * @ORM\Column(name="poste", type="string", length=255)
     */
    private $poste;

    /**
     * @ORM\OneToOne(targetEntity="User", cascade={"persist"})
     */
    private $user;

    /**
    *@ORM\OneToMany(targetEntity="Conge", mappedBy="employes")
    */
    private $conges;

    public function __construct()
    {
        $this->conges=new\Doctrine\Common\Collections\ArrayCollection();

    }

    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set nom
     *
     * @param string $nom
     *
     * @return Employe
     */
    public function setNom($nom)
    {
        $this->nom = $nom;

        return $this;
    }

    /**
     * Get nom
     *
     * @return string
     */
    public function getNom()
    {
        return $this->nom;
    }

    /**
     * Set prenom
     *
     * @param string $prenom
     *
     * @return Employe
     */
    public function setPrenom($prenom)
    {
        $this->prenom = $prenom;

        return $this;
    }

    /**
     * Get prenom
     *
     * @return string
     */
    public function getPrenom()
    {
        return $this->prenom;
    }

    /**
     * Set cin
     *
     * @param integer $cin
     *
     * @return Employe
     */
    public function setCin($cin)
    {
        $this->cin = $cin;

        return $this;
    }

    /**
     * Get cin
     *
     * @return int
     */
    public function getCin()
    {
        return $this->cin;
    }

    /**
     * Set dateNaissance
     *
     * @param \DateTime $dateNaissance
     *
     * @return Employe
     */
    public function setDateNaissance($dateNaissance)
    {
        $this->dateNaissance = $dateNaissance;

        return $this;
    }

    /**
     * Get dateNaissance
     *
     * @return \DateTime
     */
    public function getDateNaissance()
    {
        return $this->dateNaissance;
    }

    /**
     * Set adresse
     *
     * @param string $adresse
     *
     * @return Employe
     */
    public function setAdresse($adresse)
    {
        $this->adresse = $adresse;

        return $this;
    }

    /**
     * Get adresse
     *
     * @return string
     */
    public function getAdresse()
    {
        return $this->adresse;
    }

    /**
     * Set sexe
     *
     * @param string $sexe
     *
     * @return Employe
     */
    public function setSexe($sexe)
    {
        $this->sexe = $sexe;

        return $this;
    }

    /**
     * Get sexe
     *
     * @return string
     */
    public function getSexe()
    {
        return $this->sexe;
    }

    /**
     * Set etatcivil
     *
     * @param string $etatcivil
     *
     * @return Employe
     */
    public function setEtatcivil($etatcivil)
    {
        $this->etatcivil = $etatcivil;

        return $this;
    }

    /**
     * Get etatcivil
     *
     * @return string
     */
    public function getEtatcivil()
    {
        return $this->etatcivil;
    }

    /**
     * Set telephone
     *
     * @param integer $telephone
     *
     * @return Employe
     */
    public function setTelephone($telephone)
    {
        $this->telephone = $telephone;

        return $this;
    }

    /**
     * Get telephone
     *
     * @return int
     */
    public function getTelephone()
    {
        return $this->telephone;
    }

    /**
     * Set ville
     *
     * @param string $ville
     *
     * @return Employe
     */
    public function setVille($ville)
    {
        $this->ville = $ville;

        return $this;
    }

    /**
     * Get ville
     *
     * @return string
     */
    public function getVille()
    {
        return $this->ville;
    }

    /**
     * Set province
     *
     * @param string $province
     *
     * @return Employe
     */
    public function setProvince($province)
    {
        $this->province = $province;

        return $this;
    }

    /**
     * Get province
     *
     * @return string
     */
    public function getProvince()
    {
        return $this->province;
    }

    /**
     * Set codepostal
     *
     * @param integer $codepostal
     *
     * @return Employe
     */
    public function setCodepostal($codepostal)
    {
        $this->codepostal = $codepostal;

        return $this;
    }

    /**
     * Get codepostal
     *
     * @return int
     */
    public function getCodepostal()
    {
        return $this->codepostal;
    }

    /**
     * Set image
     *
     * @param string $image
     *
     * @return Employe
     */
    public function setImage($image)
    {
        $this->image = $image;

        return $this;
    }

    /**
     * Get image
     *
     * @return string
     */
    public function getImage()
    {
        return $this->image;
    }

    /**
     * Set diplome
     *
     * @param string $diplome
     *
     * @return Employe
     */
    public function setDiplome($diplome)
    {
        $this->diplome = $diplome;

        return $this;
    }

    /**
     * Get diplome
     *
     * @return string
     */
    public function getDiplome()
    {
        return $this->diplome;
    }

    /**
     * Set experience
     *
     * @param string $experience
     *
     * @return Employe
     */
    public function setExperience($experience)
    {
        $this->experience = $experience;

        return $this;
    }

    /**
     * Get experience
     *
     * @return string
     */
    public function getExperience()
    {
        return $this->experience;
    }

    /**
     * Set poste
     *
     * @param string $poste
     *
     * @return Employe
     */
    public function setPoste($poste)
    {
        $this->poste = $poste;

        return $this;
    }

    /**
     * Get poste
     *
     * @return string
     */
    public function getPoste()
    {
        return $this->poste;
    }

    /**
     * Add conge
     *
     * @param \RH\GRHBundle\Entity\Conge $conge
     *
     * @return Employe
     */
    public function addConge(\RH\GRHBundle\Entity\Conge $conge)
    {
        $this->conges[] = $conge;

        return $this;
    }

    /**
     * Remove conge
     *
     * @param \RH\GRHBundle\Entity\Conge $conge
     */
    public function removeConge(\RH\GRHBundle\Entity\Conge $conge)
    {
        $this->conges->removeElement($conge);
    }

    /**
     * Get conges
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getConges()
    {
        return $this->conges;
    }

    public function __toString(){
        // to show the name  selected
       return ($this->nom);
        // to show the id  selected
        //return $this->id;
    }

    /**
     * Set user
     *
     * @param \RH\GRHBundle\Entity\User $user
     *
     * @return Employe
     */
    public function setUser(\RH\GRHBundle\Entity\User $user = null)
    {
        $this->user = $user;

        return $this;
    }

    /**
     * Get user
     *
     * @return \RH\GRHBundle\Entity\User
     */
    public function getUser()
    {
        return $this->user;
    }
}

//controleur employe

public function profileAction(Request $request )

    {

             $em = $this->getDoctrine()->getManager();

             $user = $this->getUser()->getId();
             $employe =$em->getRepository(Employe:: class)->find($user);

             return $this->render('profile.html.twig' ,['employe' => $employe] ); 

    }
 //EmployeRepository

        public function findAction($user)
        {   

             return $this->createQueryBuilder()
            ->select( 'employe' )
            ->from( 'RHGRHBundle:Employe', 'employe' )
            ->where( 'employe.user = : Id' )

            ->setParameter('Id', $userId)
            ->getQuery()
            ->getResult
        ;

        }

voila quelque capture :

https://scontent.ftun3-1.fna.fbcdn.net/v/t1.15752-9/58381610_1038876872978244_4239637560197906432_n.png?_nc_cat=109&_nc_ht=scontent.ftun3-1.fna&oh=289d125affb7d350f69ae8d41907500d&oe=5D3899B6

https://scontent.ftun3-1.fna.fbcdn.net/v/t1.15752-9/58883037_2326473147591194_1707803525171380224_n.png?_nc_cat=104&_nc_ht=scontent.ftun3-1.fna&oh=887cbb4b631208cb5465b8577990be3c&oe=5D71DC82

https://scontent.ftun3-1.fna.fbcdn.net/v/t1.15752-9/58462721_465811120826168_3917280185660997632_n.png?_nc_cat=103&_nc_ht=scontent.ftun3-1.fna&oh=a417e3b148e7bbba5bd231c21cf9668a&oe=5D299615

Ce que je veux

Que je veut faire finalement est le suivant si tu est déjà inscrit et connecté sur ton compte deux chose tu peut les faire donc si tu as déjà remplir tes infos personnelles une chose comme il est afficher dans la 1 ère capture s'affiche et le bouton "saisir les infos personnelles " ne s'affiche pas sinon ce dernier s'affiche et tu remplit alors le formulaire d'ajout des infos personnelles .

Ce que j'obtiens

a chaque fois que j’exécute la requête il m'affiche le même message quelque soit l’utilisateur que j'ajoute.

merci pour m'aider :) .

2 réponses


Lartak
Réponse acceptée

Bonsoir.
Je souhaiterais savoir quel est le code sur lequel nous devons nous baser, celui qui est copié dans ton sujet ou celui de tes screens ?

a chaque fois que j’exécute la requête il m'affiche le même message

Et, quel est ce message ?

rouaob
Auteur

bonjour
le message dans cette capture : https://scontent.ftun3-1.fna.fbcdn.net/v/t1.15752-9/58381610_1038876872978244_4239637560197906432_n.png?_nc_cat=109&_nc_ht=scontent.ftun3-1.fna&oh=289d125affb7d350f69ae8d41907500d&oe=5D3899B6

quelque soit le compte que je login avec il m'affiche que j'ai deja entrer mes infos personnelles alors que c'est pas le cas