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 :

Recupération d'une entité dans une autre [2.x]


Sujet :

Symfony PHP

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    125
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 125
    Points : 108
    Points
    108
    Par défaut Recupération d'une entité dans une autre
    Bonjour
    j'ai mes deux entité que voici:
    client
    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
    <?php
     
    namespace Gestion\ClientBundle\Entity;
     
    use Doctrine\ORM\Mapping as ORM;
     
    /**
     * Client
     *
     * @ORM\Table()
     * @ORM\Entity(repositoryClass="Gestion\ClientBundle\Entity\ClientRepository")
     */
    class Client
    {
        /**
         * @var integer
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $id;
     
        /**
         * @var \DateTime
         *
         * @ORM\Column(name="date", type="datetime")
         */
        private $date;
     
        /**
         * @var string
         *
         * @ORM\Column(name="nom", type="string", length=70)
         */
        private $nom;
     
        /**
         * @var string
         *
         * @ORM\Column(name="prenom", type="string", length=80)
         */
        private $prenom;
     
        /**
         * @var integer
         *
         * @ORM\Column(name="telephone", type="integer")
         */
        private $telephone;
     
        /**
         * @ORM\ManyToOne(targetEntity="Adminsite\BasesBundle\Entity\Niveaux")
         * @ORM\JoinColumn(nullable=false)
         */
        private $niveaux;
     
        public function __construct()
        {
          $this->date = new \Datetime();
        }
     
        /**
         * Get id
         *
         * @return integer 
         */
        public function getId()
        {
            return $this->id;
        }
     
        /**
         * Set date
         *
         * @param \DateTime $date
         * @return Client
         */
        public function setDate($date)
        {
            $this->date = $date;
     
            return $this;
        }
     
        /**
         * Get date
         *
         * @return \DateTime 
         */
        public function getDate()
        {
            return $this->date;
        }
     
        /**
         * Set nom
         *
         * @param string $nom
         * @return Client
         */
        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 Client
         */
        public function setPrenom($prenom)
        {
            $this->prenom = $prenom;
     
            return $this;
        }
     
        /**
         * Get prenom
         *
         * @return string 
         */
        public function getPrenom()
        {
            return $this->prenom;
        }
     
        /**
         * Set telephone
         *
         * @param integer $telephone
         * @return Client
         */
        public function setTelephone($telephone)
        {
            $this->telephone = $telephone;
     
            return $this;
        }
     
        /**
         * Get telephone
         *
         * @return integer 
         */
        public function getTelephone()
        {
            return $this->telephone;
        }
     
        /**
         * Set niveaux
         *
         * @param \Adminsite\BasesBundle\Entity\Niveaux $niveaux
         * @return Client
         */
        public function setNiveaux(\Adminsite\BasesBundle\Entity\Niveaux $niveaux)
        {
            $this->niveaux = $niveaux;
     
            return $this;
        }
     
        /**
         * Get niveaux
         *
         * @return \Adminsite\BasesBundle\Entity\Niveaux 
         */
        public function getNiveaux()
        {
            return $this->niveaux;
        }
    }
    niveaux
    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
    <?php
     
    namespace Adminsite\BasesBundle\Entity;
     
    use Doctrine\ORM\Mapping as ORM;
     
    /**
     * Niveaux
     *
     * @ORM\Table()
     * @ORM\Entity(repositoryClass="Adminsite\BasesBundle\Entity\NiveauxRepository")
     */
    class Niveaux
    {
        /**
         * @var integer
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $id;
     
        /**
         * @var string
         *
         * @ORM\Column(name="intitule", type="string", length=255)
         */
        private $intitule;
     
        /**
         * @var integer
         *
         * @ORM\Column(name="classement", type="integer")
         */
        private $classement;
     
        /**
         * @var string
         *
         * @ORM\Column(name="commentaires", type="string", length=255)
         */
        private $commentaires;
     
     
        /**
         * Get id
         *
         * @return integer 
         */
        public function getId()
        {
            return $this->id;
        }
     
        /**
         * Set intitule
         *
         * @param string $intitule
         * @return Niveaux
         */
        public function setIntitule($intitule)
        {
            $this->intitule = $intitule;
     
            return $this;
        }
     
        /**
         * Get intitule
         *
         * @return string 
         */
        public function getIntitule()
        {
            return $this->intitule;
        }
     
        /**
         * Set classement
         *
         * @param integer $classement
         * @return Niveaux
         */
        public function setClassement($classement)
        {
            $this->classement = $classement;
     
            return $this;
        }
     
        /**
         * Get classement
         *
         * @return integer 
         */
        public function getClassement()
        {
            return $this->classement;
        }
     
        /**
         * Set commentaires
         *
         * @param string $commentaires
         * @return Niveaux
         */
        public function setCommentaires($commentaires)
        {
            $this->commentaires = $commentaires;
     
            return $this;
        }
     
        /**
         * Get commentaires
         *
         * @return string 
         */
        public function getCommentaires()
        {
            return $this->commentaires;
        }
    }
    je cherche à faire un ajout en bdd avec ma méthode ajoutAction:
    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
    <?php
     
    namespace Gestion\ClientBundle\Controller;
     
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Gestion\ClientBundle\Entity\Client;
     
    class GestionClientController extends Controller
    {
        public function indexAction()
        {
            $repository = $this->getDoctrine()
                       ->getManager()
                       ->getRepository('GestionClientBundle:Client');
     
               /* il faudra les classer par date de dernière prestation */
            $listeclientnom = $repository->findBy(array('nom' => 'udyr'));
            $listeclientprenom = $repository->findBy(array('prenom' => 'udyr'));
     
            return $this->render('GestionClientBundle:Default:rechGestionClient.html.twig', array('listeclientnom' => $listeclientnom, 'listeclientprenom' => $listeclientprenom ));
        }
     
     
        public function nouveauAction()
        {
            return $this->render('GestionClientBundle:Default:nouveauGestionClient.html.twig');
        }
     
     
        public function ficheAction($id)
        {
            $repository = $this->getDoctrine()
                               ->getManager()
                               ->getRepository('GestionClientBundle:Client');
     
                    // On récupère l'entité correspondant à l'id $id
                    $client = $repository->find($id);
     
                    // $article est donc une instance de Sdz\BlogBundle\Entity\Article
     
                    // Ou null si aucun article n'a été trouvé avec l'id $id
                    if($client === null)
                    {
                      throw $this->createNotFoundException('Client[id='.$id.'] inexistant.');
                    }
     
                    return $this->render('GestionClientBundle:Default:ficheGestionClient.html.twig', array('client' => $client));
        }
     
        public function ajoutAction()
        {
            $client = new Client();
            $client->setNom('ahri');
            $client->setPrenom('Olaf');
            $client->setTelephone('0606060606');
            $client->setNiveaux($niveaux);
     
            $em = $this->getDoctrine()->getManager();
     
            $em->persist($client);
     
     
            $em->flush();
     
            return $this->redirect( $this->generateUrl('rech_client') );
        }
    }
    Comment remplir le champ lié niveaux du client ?

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    125
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 125
    Points : 108
    Points
    108
    Par défaut
    C'est bon :s
    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
        public function ajoutAction()
        {
            $repository = $this->getDoctrine()
                               ->getManager()
                               ->getRepository('AdminsiteBasesBundle:Niveaux');
     
                    // On récupère l'entité correspondant à l'id $id
                    $niveaux = $repository->find('1');
     
            $client = new Client();
            $client->setNom('ahri');
            $client->setPrenom('Olaf');
            $client->setTelephone('0606060606');
            $client->setNiveaux($niveaux);
     
            $em = $this->getDoctrine()->getManager();
            // Étape 1 : On « persiste » l'entité
            $em->persist($client);
     
            // Étape 2 : On « flush » tout ce qui a été persisté avant
            $em->flush();
            if ($this->getRequest()->getMethod() == 'POST') {
            $this->get('session')->getFlashBag()->add('info', 'Client bien enregistré');}
            return $this->redirect( $this->generateUrl('rech_client') );
        }
    Je laisse le post et je met résolu...

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

Discussions similaires

  1. [Toutes versions] coller les données d'une plage d'une cellule dans une cellule d'une autre feuille[VBA]
    Par arthson dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 24/01/2012, 17h37
  2. Réponses: 7
    Dernier message: 25/03/2011, 10h52
  3. Réponses: 4
    Dernier message: 15/10/2009, 13h33
  4. [XL-2007] Afficher une checkbox dans une feuille si une checkbox d'une autre feuille est cochée
    Par JessieCoutas dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 18/08/2009, 13h35
  5. Recherche une valeur d'une cellule dans une colonne d'une autre feuille
    Par kourria dans le forum Macros et VBA Excel
    Réponses: 8
    Dernier message: 21/06/2007, 13h48

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