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

 PHP Discussion :

Afficher le nom de l'utilisateur qui ajoute une sortie


Sujet :

PHP

  1. #1
    Futur Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Novembre 2020
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2020
    Messages : 9
    Points : 9
    Points
    9
    Par défaut Afficher le nom de l'utilisateur qui ajoute une sortie
    Bonojur a tous
    je travaille sur une application qui doit permettre à des étudiants de poster des idées de sorties sur une platemforme.
    Le problème c'est que je n'arrive pas à recupèrer et à afficher le nom de l'utilisateur qui a posté la sortie (colonne organisateur) , ni l'etat de la sortie (colonne etat) qui devrait normalement s'initialiser avec la valeur 'Créee .

    voici le résultat sur la page web :
    Nom : 2020-11-16 (2)_LI.jpg
Affichages : 86
Taille : 638,4 Ko


    voici mon 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
    36
    37
    38
    39
     
     
    /**
         * @Route("/sortie/ajouter", name="sortie_ajouter")
         * @param EntityManagerInterface $em
         * @param Request $request
         * @return RedirectResponse|Response
         */
            public function ajouter(EntityManagerInterface $em, Request $request)
     
        {
     
            $sortie = new Sortie();
            $sortie->setDateCreation(new DateTime);
            $sortie->setOrganisateur($this->getUser());
     
     
     
     
            $sortieForm = $this->createForm(AjoutSortieType::class, $sortie);
     
            $sortieForm->handleRequest($request);
            if ($sortieForm->isSubmitted() && $sortieForm->isValid()) {
              $etat=new Etat();
               $em->persist($etat);
     
                $em->flush($etat);
                $sortie->setEtat($etat);
                $em->persist($sortie);
                $em->flush();
     
                $this->addFlash('success', 'Bravo , votre sortie est ajoutée !');
                return $this->redirectToRoute("sortie_afficher"
     
                );
            }
            return $this->render("sortie/ajouter.html.twig", [
                "sortieForm" => $sortieForm->createView()
            ]);

    et voici mon entité Sortie :
    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
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
     
     
    **
     * @ORM\Entity(repositoryClass=SortieRepository::class)
     */
    class Sortie
    {
        /**
         *
         * @ORM\Id
         * @ORM\GeneratedValue
         * @ORM\Column(type="integer")
         */
        private $id;
        /**
         * @ORM\Column(type="datetime",nullable=true)
         */
        private $dateCreation;
     
     
        /**
         * @Assert\NotBlank(message="Merci de renseigner un nom pour la sortie")
         * @Assert\Length(max=255,maxMessage=" Maximum 255 caractères !")
         * @ORM\Column(type="string",length=255)
         */
        private  $nom;
        /**
         *
         * @ORM\Column(type="datetime",nullable=true)
         */
        private  $dateHeureDebut;
        /**
         * @ORM\Column(type="integer",nullable=true)
         */
        private  $duree;
        /**
         * @ORM\Column(type="datetime",nullable=true)
         */
        private  $dateLimiteInscription;
        /**
         * @Assert\Length (min=10,minMessage=" C'est trop court !")
         * @ORM\Column(type="text")
         */
        private  $infosSortie;
     
        /**
         *
         * @ORM\Column(type="text",length=50)
         */
        private  $nbInscriptionMax;
        /**
         *
         * @ORM\Column(type="boolean",length=50,nullable=true)
         */
        private  $archive;
     
        /**
         * @ORM\ManyToMany(targetEntity="App\Entity\Participant" , inversedBy="mesSorties")
         */
        private  $participants;
     
        /**
         *
         * @ORM\ManyToOne(targetEntity="App\Entity\Participant" , inversedBy="jorganise")
         * @ORM\JoinColumn(nullable=false)
         */
        private  $organisateur;
     
        /**
         * @ORM\ManyToOne(targetEntity="App\Entity\Campus" , inversedBy="sorties")
         * @ORM\JoinColumn(nullable=false)
         */
        private  $campusOrganisateur;
        /**
         *
         * @ORM\ManyToOne(targetEntity="App\Entity\Etat" , inversedBy="sorties")
         * @ORM\JoinColumn(nullable=false)
         */
        private  $etat;
        /**
         * @ORM\ManyToOne(targetEntity="App\Entity\Lieu" , inversedBy="sorties")
         * @ORM\JoinColumn(nullable=false)
         */
        private  $lieu;
     
        /**
         * @return mixed
         */
        public function getParticipants()
        {
            return $this->participants;
        }
     
        /**
         * @param mixed $participants
         */
        public function setParticipants($participants): void
        {
            $this->participants = $participants;
        }
     
        /**
         * @return mixed
         */
        public function getOrganisateur()
        {
            return $this->organisateur;
        }
     
        /**
         * @param mixed $organisateur
         */
        public function setOrganisateur($organisateur): void
        {
            $this->organisateur = $organisateur;
        }
     
        /**
         * @return mixed
         */
        public function getCampusOrganisateur()
        {
            return $this->campusOrganisateur;
        }
     
        /**
         * @param mixed $campusOrganisateur
         */
        public function setCampusOrganisateur($campusOrganisateur): void
        {
            $this->campusOrganisateur = $campusOrganisateur;
        }
     
        /**
         * @return mixed
         */
        public function getDateCreation()
        {
            return $this->dateCreation;
        }
     
        /**
         * @param mixed $dateCreation
         */
        public function setDateCreation($dateCreation): void
        {
            $this->dateCreation = $dateCreation;
        }
     
        /**
         * @return mixed
         */
        public function getEtat()
        {
            return $this->etat;
        }
     
        /**
         * @param mixed $etat
         */
        public function setEtat($etat): void
        {
            $this->etat = $etat;
        }
     
     
     
        /**
         * @return mixed
         */
        public function getLieu()
        {
            return $this->lieu;
        }
     
        /**
         * @param mixed $lieu
         * @return Sortie
         */
        public function setLieu($lieu)
        {
            $this->lieu = $lieu;
            return $this;
        }
     
     
     
     
     
     
     
        /**
         * @return mixed
         */
        public function getArchive()
        {
            return $this->archive;
        }
     
        /**
         * @param mixed $archive
         */
        public function setArchive($archive): void
        {
            $this->archive = $archive;
        }
     
     
     
        /**
         * @return mixed
         */
        public function getId()
        {
            return $this->id;
        }
     
        /**
         * @param mixed $id
         */
        public function setId($id): void
        {
            $this->id = $id;
        }
     
        /**
         * @return mixed
         */
        public function getNbInscriptionMax()
        {
            return $this->nbInscriptionMax;
        }
     
        /**
         * @param mixed $nbInscriptionMax
         */
        public function setNbInscriptionMax($nbInscriptionMax): void
        {
            $this->nbInscriptionMax = $nbInscriptionMax;
        }
     
     
        /**
         * @return mixed
         */
        public function getNom()
        {
            return $this->nom;
        }
     
        /**
         * @param mixed $nom
         */
        public function setNom($nom): void
        {
            $this->nom = $nom;
        }
     
        /**
         * @return mixed
         */
        public function getDateHeureDebut()
        {
            return $this->dateHeureDebut;
        }
     
        /**
         * @param mixed $dateHeureDebut
         */
        public function setDateHeureDebut($dateHeureDebut): void
        {
            $this->dateHeureDebut = $dateHeureDebut;
        }
     
        /**
         * @return mixed
         */
        public function getDuree()
        {
            return $this->duree;
        }
     
        /**
         * @param mixed $duree
         */
        public function setDuree($duree): void
        {
            $this->duree = $duree;
        }
     
        /**
         * @return mixed
         */
        public function getDateLimiteInscription()
        {
            return $this->dateLimiteInscription;
        }
     
        /**
         * @param mixed $dateLimiteInscription
         */
        public function setDateLimiteInscription($dateLimiteInscription): void
        {
            $this->dateLimiteInscription = $dateLimiteInscription;
        }
     
        /**
         * @return mixed
         */
        public function getInfosSortie()
        {
            return $this->infosSortie;
        }
     
        /**
         * @param mixed $infosSortie
         */
        public function setInfosSortie($infosSortie): void
        {
            $this->infosSortie = $infosSortie;
        }
    et voici mon entite Etat (entité associé)

    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
     
    /**
     * @ORM\Entity(repositoryClass=EtatRepository::class)
     */
    class Etat
    {
        /**
         * @ORM\Id
         * @ORM\GeneratedValue
         * @ORM\Column(type="integer")
         */
        private $id;
     
     
        /**
         *
         * @ORM\Column(type="string",length=100 , options={"default":"Créee"})
         */
        private  $libelle='Créee';
     
     
        /**
         * @ORM\OneToMany(targetEntity="App\Entity\Sortie" , mappedBy="etat")
         */
        private  $sorties;
     
     
        /**
         * Etat constructor.
         *
         */
        public function __construct()
        {
            $this->sorties = new ArrayCollection();
     
        }
     
     
        /**
         * @return mixed
         */
        public function getSorties()
        {
            return $this->sorties;
        }
     
        /**
         * @param mixed $sorties
         */
        public function setSortie($sorties): void
        {
            $this->sorties = $sorties;
        }
     
        /**
         * @return mixed
         */
        public function getId()
        {
            return $this->id;
        }
     
     
     
     
        /**
         * @param mixed $id
         */
        public function setId($id): void
        {
            $this->id = $id;
        }
     
        /**
         * @return mixed
         */
        public function getLibelle()
        {
            return $this->libelle;
        }
     
        /**
         * @param mixed $libelle
         */
        public function setLibelle($libelle): void
        {
            $this->libelle = $libelle;
        }
    merci pour votre aide !

  2. #2
    Expert éminent sénior
    Avatar de mathieu
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    10 235
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 10 235
    Points : 15 532
    Points
    15 532
    Par défaut
    il y a peut être un soucis dans l'affichage, montrez nous le fichier twig qui génère cette page.

  3. #3
    Futur Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Novembre 2020
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2020
    Messages : 9
    Points : 9
    Points
    9
    Par défaut
    voici mon fichier twig :

    Code twig : 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
    {% extends 'base.html.twig' %}
     
    {% block body %}
        <h2> Ajouter une sortie </h2>
     <div class="container">
     
         <div class="form">
             <br>
             {{ form_start(sortieForm) }}
             {{ form_widget(sortieForm) }}
             <button type="submit">Envoyer !</button>
             {{ form_end(sortieForm) }}
         </div>
     
     
     </div>
     
     
    {% endblock %}
     
            {% block title %}Ajouter une sortie! |*{{ parent() }}{% endblock %}


    et voici le formulaire d'ajout

    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
    class AjoutSortieType extends AbstractType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $builder
     
     
                ->add('nom',TextType::class, [
                    'label' => 'Nom de la sortie'
                ])
                ->add('dateHeureDebut',DateType::class,[
                    'label' => 'date et heure de la sortie'
                ])
                ->add('dateLimiteInscription',DateType::class,[
                    'label'=>'date limite d\'inscription'
                ])
     
                ->add('nbInscriptionMax', IntegerType::class,[
                    'label' => 'nombres de places'
                ])
                ->add('duree', IntegerType::class, [
                    'label' => 'durée en minutes'
                ])
                ->add('infosSortie',TextareaType::class,[
                    'label' => 'Informations',
                    'attr'=>[
                        'placeholder'=>'decrivez ici la sortie'
                    ]
                ])
     
     
                ->add('campusOrganisateur',EntityType::class,[
                                'label'=>'Campus',
                                'class'=> Campus::class,])
     
     
                ->add('lieu',EntityType::class,[
                    'label'=>'Lieu',
                    'class'=>Lieu::class,
                ])
          ;
        }
     
        public function configureOptions(OptionsResolver $resolver)
        {
            $resolver->setDefaults([
                'data_class' => Sortie::class,
            ]);
        }
    }

  4. #4
    Futur Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Novembre 2020
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2020
    Messages : 9
    Points : 9
    Points
    9
    Par défaut
    j'ai effectué quelques changement et maintenant j'ai un autre message d'erreur



    Nom : 2020-11-16 (3).png
Affichages : 65
Taille : 65,2 Ko


    voici le fichier twig pour l' affichage de l'ensemble des sorties sous forme de tableau :






    Code twig : 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
    {% extends 'base.html.twig' %}
     
    {% block title %} Liste des sorties | Sortir.com !{% endblock %}
     
    {% block body %}
        <nav class="nav justify-content-end"  id="nav">
            {% if app.user %}
     
                <a href="#"  style="color: whitesmoke">Villes  | </a>
                <a href="#" style="color: whitesmoke" >Campus  | </a>
                <a href="#" style="color: whitesmoke" >Accueil  | </a>
                <a href="{{ path("profil_index") }}" style="color: whitesmoke">Mon profil |</a>
                <a href="{{ path("app_logout") }}" style="color: whitesmoke" >Se déconnecter  </a>
     
     
           {% endif %}
        </nav>
     
     
        <h2>Filtrer les sorties</h2>
     
     
     <div class="container">
            <table class="table table-striped table-hover">
                <thead>
                  <tr >
                    <th scope="col">Nom de la sortie</th>
                    <th scope="col">Date de la sortie</th>
                    <th scope="col">Clôture</th>
                    <th scope="col">inscrits/places</th>
                    <th scope="col">Etat</th>
                    <th scope="col">Durée</th>
                    <th scope="col">Inscrit</th>
                    <th scope="col">Organisateur</th>
                    <th scope="col">Actions</th>
                 </tr>
                </thead>
     
     
            <tbody>
          {% for sortie in sorties %}
                   <tr >
                      <td>{{ sortie.nom }}</td>
                      <td>{{ sortie.dateHeureDebut |date('Y-m-d') }}</td>
                      <td>{{ sortie.dateLimiteInscription |date('Y-m-d')}}</td>
                      <td>{{ sortie.nbInscriptionMax |length}}/{{ sortie.nbInscriptionMax |length}}</td>
                       <td>{{ sortie.etat }}</td>
                       <td>{{ sortie.duree }}</td>
                      <td>{{sortie.organisateur }}</td>
                     <td> Supprimer-Afficher_Se désister_Modifier_Publier_S'inscrire</td>
                </tr>
          {% endfor %}
              </tbody>
          </table>
     
         <a class="btn btn-outline-secondary btn-lg " href="{{ path('sortie_ajouter') }}" role="button">Créer une sortie</a>
     </div>
     
     
    {% endblock %}



    voici ma relation :



    Nom : 2020-11-16 (6).png
Affichages : 77
Taille : 26,8 Ko

  5. #5
    Expert éminent sénior

    Avatar de -Nikopol-
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2013
    Messages
    2 174
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Haute Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Enseignement

    Informations forums :
    Inscription : Mai 2013
    Messages : 2 174
    Points : 11 289
    Points
    11 289
    Billets dans le blog
    5
    Par défaut
    Il te faut la mthode toString :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    public function __toString()
        {
            return $this->title;
        }
    ca peut etre autre chose que title

  6. #6
    Futur Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Novembre 2020
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2020
    Messages : 9
    Points : 9
    Points
    9
    Par défaut
    Oui c'était bien la methode --toString() qu'il manquait .
    Problème résolu ;
    MERCI BEAUCOUP !

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

Discussions similaires

  1. Réponses: 0
    Dernier message: 29/09/2010, 11h53
  2. Réponses: 2
    Dernier message: 27/06/2009, 12h54
  3. Réponses: 1
    Dernier message: 02/09/2008, 23h13
  4. [MySQL] Trouver le nom de l'utilisateur qui se connecte(debutant)
    Par Natsume dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 27/10/2006, 13h19
  5. Retrouver le nom d'un utilisateur qui a verrouillé une ligne
    Par Laurent Dardenne dans le forum Administration
    Réponses: 24
    Dernier message: 18/09/2004, 17h01

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