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

Langage PHP Discussion :

Symfony2-Inclure un form dans un popup


Sujet :

Langage PHP

  1. #1
    Inactif  
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2014
    Messages
    58
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2014
    Messages : 58
    Points : 53
    Points
    53
    Par défaut Symfony2-Inclure un form dans un popup
    Bonjour a tous
    je suis entrain de développer une application de gestion sous symfony2. j'ai un formulaire qui contient une liste de fournisseurs,un bouton qui permet d'ajouter un nouveau element et la possibilité de modifier et afficher les informations de chaque fournisseur.le soucis c'est que je veux que l'ajout,la modification et l'affichage soient sous forme popup.J'ai essayé de suivre une méthode logique mais une erreur toujours s'affiche'Variable "form" does not exist.'je vous donne le code pour mieux comprendre:
    FournisseurController:
    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
     
     
    namespace Centre\CentreBundle\Controller;
     
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\Security\Core\Exception\AccessDeniedException;
    use Centre\CentreBundle\Entity\Fournisseur;
    use Centre\CentreBundle\Form\FournisseurType;
    /**
     * Categorie controller.
     *
     */
    class FournisseurController extends Controller
    {
     
        /**
         * Lists all Categorie entities.
         *
         */
        public function indexAction()
        {
            $em = $this->getDoctrine()->getManager();
     
            $entities1 = $em->getRepository('CentreBundle:Fournisseur')->findAll();
     
     
            $entities  = $this->get('knp_paginator')->paginate($entities1,$this->get('request')->query->get('page', 1)/*page number*/,5/*limit per page*/
        );
     
            return $this->render('CentreBundle:Default:fournisseur/index.html.twig', array(
                'entities' => $entities,
            ));
        }
        /**
         * Creates a new Categorie entity.
         *
         */
        public function createAction(Request $request)
        {
            $entity = new Fournisseur();
            $form = $this->createCreateForm($entity);
            $form->handleRequest($request);
     
            if ($form->isValid()) {
                $em = $this->getDoctrine()->getManager();
                $em->persist($entity);
                $em->flush();
     
                return $this->redirect($this->generateUrl('fournisseur_show', array('id' => $entity->getId())));
            }
     
            return $this->render('CentreBundle:Default:fournisseur/new.html.twig', array(
                'entity' => $entity,
                'form'   => $form->createView(),
            ));
        }
     
        /**
         * Creates a form to create a Categorie entity.
         *
         * @param Categorie $entity The entity
         *
         * @return \Symfony\Component\Form\Form The form
         */
        private function createCreateForm(Fournisseur $entity)
        {
            $form = $this->createForm(new FournisseurType(), $entity, array(
                'action' => $this->generateUrl('fournisseur_create'),
                'method' => 'POST',
            ));
     
            $form->add('submit', 'submit', array(
                    'label' => 'Enregistrer',
                    'attr'=> array(
                        'class' => 'btn btn-primary',
                    )
                )
            );
            return $form;
        }
     
        /**
         * Displays a form to create a new Categorie entity.
         *
         */
        public function newAction()
        {
     
            $entity = new Fournisseur();
            $form   = $this->createCreateForm($entity);
     
            return $this->render('CentreBundle:Default:fournisseur/new.html.twig', array(
                'entity' => $entity,
                'form'   => $form->createView(),
            ));
        }
     
        /**
         * Finds and displays a Categorie entity.
         *
         */
        public function showAction($id)
        {
            $em = $this->getDoctrine()->getManager();
     
            $entity = $em->getRepository('CentreBundle:Fournisseur')->find($id);
     
            if (!$entity) {
                throw $this->createNotFoundException('Unable to find fournisseur entity.');
            }
     
            $deleteForm = $this->createDeleteForm($id);
     
            return $this->render('CentreBundle:Default:fournisseur/show.html.twig', array(
                'entity'      => $entity,
                'delete_form' => $deleteForm->createView(),
            ));
        }
     
        /**
         * Displays a form to edit an existing Categorie entity.
         *
         */
        public function editAction($id)
        {
     
            $em = $this->getDoctrine()->getManager();
     
            $entity = $em->getRepository('CentreBundle:Fournisseur')->find($id);
     
            if (!$entity) {
                throw $this->createNotFoundException('Unable to find Fournisseur entity.');
            }
     
            $editForm = $this->createEditForm($entity);
            $deleteForm = $this->createDeleteForm($id);
     
            return $this->render('CentreBundle:Default:fournisseur/edit.html.twig', array(
                'entity'      => $entity,
                'edit_form'   => $editForm->createView(),
                'delete_form' => $deleteForm->createView(),
            ));
        }
     
        /**
        * Creates a form to edit a Categorie entity.
        *
        * @param Categorie $entity The entity
        *
        * @return \Symfony\Component\Form\Form The form
        */
        private function createEditForm(Fournisseur $entity)
        {
            $form = $this->createForm(new FournisseurType(), $entity, array(
                'action' => $this->generateUrl('fournisseur_update', array('id' => $entity->getId())),
                'method' => 'PUT',
            ));
     
            $form->add('submit', 'submit', array(
                    'label' => 'Enregistrer',
                    'attr'=> array(
                        'class' => 'btn btn-primary',
                    )
                )
            );
            return $form;
        }
        /**
         * Edits an existing Categorie entity.
         *
         */
        public function updateAction(Request $request, $id)
        {
            $em = $this->getDoctrine()->getManager();
     
            $entity = $em->getRepository('CentreBundle:Fournisseur')->find($id);
     
            if (!$entity) {
                throw $this->createNotFoundException('Unable to find Fournisseur entity.');
            }
     
            $deleteForm = $this->createDeleteForm($id);
            $editForm = $this->createEditForm($entity);
            $editForm->handleRequest($request);
     
            if ($editForm->isValid()) {
                $em->flush();
     
                return $this->redirect($this->generateUrl('fournisseur', array('id' => $id)));
            }
     
            return $this->render('CentreBundle:Default:fournisseur/edit.html.twig', array(
                'entity'      => $entity,
                'edit_form'   => $editForm->createView(),
                'delete_form' => $deleteForm->createView(),
            ));
        }
        /**
         * Deletes a Categorie entity.
         *
         */
        public function deleteAction(Request $request, $id)
        {
     
            $form = $this->createDeleteForm($id);
            $form->handleRequest($request);
     
            if ($form->isValid()) {
                $em = $this->getDoctrine()->getManager();
                $entity = $em->getRepository('CentreBundle:Fournisseur')->find($id);
     
                if (!$entity) {
                    throw $this->createNotFoundException('Unable to find Fournisseur entity.');
                }
     
                $em->remove($entity);
                $em->flush();
            }
     
            return $this->redirect($this->generateUrl('fournisseur'));
        }
     
        /**
         * Creates a form to delete a Categorie entity by id.
         *
         * @param mixed $id The entity id
         *
         * @return \Symfony\Component\Form\Form The form
         */
        private function createDeleteForm($id)
        {
            return $this->createFormBuilder()
                ->setAction($this->generateUrl('fournisseur_delete', array('id' => $id)))
                ->setMethod('DELETE')
                ->add('submit', 'submit', array(
                    'label' => 'Supprimer',
                    'attr'   => array(
                        "class" => 'btn btn-danger'
                    ),
                ))
                ->getForm()
            ;
        }
    }
    //index.html.twig

    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
     
     
     
    {% extends '::layout/layout.html.twig' %}
     
    {% block title %}List des fournisseurs{% endblock %}
    {% block pageTitle %}{{ ' List des fournisseurs'|upper }}{% endblock %}
     
    {% block breadcrumb %}
        {# this is a expmple how to use a breadcrumb (menu de navigation ) #}
     
        <li>
            <a>List des fournisseurs d'energie</a>
        </li>
    {% endblock %}
     
    {% block body -%}
     
     
         <div class="container">
    		<div class="row">
     
      <div class="span3">
     
      </div>
     
     
                     <section class="span9">
        <div >
            <h3><span class="light">Mes</span> fournisseurs  
               </h3>
        </div>
     <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
     Ajouter un nouveau fournisseur
    </button>
     
    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">Modal title</h4>
          </div>
          <div class="modal-body">
             {% include 'CentreBundle:Default:fournisseur/new.html.twig'%}
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
          </div>
        </div>
      </div>
    </div>
     
        <table class="table table-theme table-striped">
            <thead>
                <tr>
     
                    <th>Nom</th>
     
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
            {% for entity in entities %}
                <tr>
                    <td> {{ entity.nomFournisseur }}</td>
     
                    <td>
                    <ul>
                            <a href="{{ path('fournisseur_show', { 'id': entity.id }) }}" class="btn btn-warning push-down-10"><i class="  icon-zoom-in"></i>Afficher</a>
                            <a href="{{ path('fournisseur_edit', { 'id': entity.id }) }}" class="btn btn-warning push-down-10"><i class=" icon-edit"></i>Modifier</a>
                    </ul>
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
     
        <div class="navigation">
        {{ knp_pagination_render(entities) }}
    </div>
        </section>
                    </div>
     
         </div>
     
        {% endblock %}
    //new.html.twig
    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
     
    {% extends '::layout/layout.html.twig' %}
     
    {% block title %}Ajouter un nouveau operateur  {% endblock %}
    {% block pageTitle %}{{ 'Ajouter un nouveau operateur '|upper }}{% endblock %}
     
    {% block breadcrumb %}
        {# this is a expmple how to use a breadcrumb (menu de navigation ) #}
        <li>
            <a>Liste des operateurs</a>
        </li>
        <li><span class="icon-chevron-right"></span></li>
        <li>
            <a>Ajouter un nouveau operateur</a>
        </li>
    {% endblock %}
     
     
    {% block body -%}
    <div class="container">
    		<div class="row">
     
      <div class="span3">
     
      </div>
     
        <section class="span9">
        <div class="underlined push-down-20">
            <h3><span class="light">Ajouter</span> un fournisseur</h3>
        </div> <!-- /title -->
     
        {{ form(form) }}
    <hr/>
            <ul class="record_actions">
        <li>
            <a href="{{ path('fournisseur') }}">
               Retour à la liste
            </a>
        </li>
    </ul>
        </section>
    </div>
    </div>
    {% endblock %}
    merci de m'aider

  2. #2
    Nouveau membre du Club

    Homme Profil pro
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 38
    Points
    38
    Billets dans le blog
    1
    Par défaut
    Bonjour
    pour le popup

    les étapes

    -1 Creation un nouveau contrôleur avec l'action ajouter ou modifier supprimer ....
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
      public function confirmationApplicationAction($id) {
            $application = $this->getDoctrine()->getRepository('WcProjetBundle:Application')->findOneById($id);
            $em = $this->getDoctrine()->getManager();
            $em->remove($application);
            $em->flush();
            return $this->redirectToRoute('wc_projet_listeApplciation');
        }
    -2 avoir un routing de confirmation de l'action
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    wc_projet_confirmationApplication:
        path:     /confirmationApplication/{id}
        defaults: { _controller: WcProjetBundle:ApplicationExe:confirmationApplication }
    - 3 action sur lien du popup



    Code : Sélectionner tout - Visualiser dans une fenêtre à part
                                    <td><button type="button" class="btn btn-info btn-lg" name="delete"  data-toggle="modal" data-target="#myModal">Supprimer</button>
    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
       <!-- Modal -->
                            <div id="myModal" class="modal fade" role="dialog">
                                <div class="modal-dialog">
     
                                    <!-- Modal content-->
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                                            <h4 class="modal-title">Delete</h4>
                                        </div>
                                        <div class="modal-body">
                                            <p>Voulez vous vraiment supprimer l'application.</p>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                            <a href="{{path('wc_projet_confirmationApplication', {'id': (application.id)})}}"> <button type="button" class="btn btn-default">Supprimer</button></a>
                                            </a>
                                        </div>
                                    </div>
     
                                </div>
                            </div>

    bonne chance

  3. #3
    Inactif  
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2014
    Messages
    58
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2014
    Messages : 58
    Points : 53
    Points
    53
    Par défaut
    merci pour la solution

  4. #4
    Inactif  
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2014
    Messages
    58
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 33
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2014
    Messages : 58
    Points : 53
    Points
    53
    Par défaut
    bein je suis pas expert en symfony je suis debutante.j'ai essayé de faire adapter votre solution a mon projet
    j'ai ajouté une nouvelle action dans mon Controleur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
     
    class FournisseurController extends Controller
    {
    public function confirmationApplicationAction($id) {
            $application = $this->getDoctrine()->getRepository('FournisseurBundle:Fournisseur')->findOneById($id);
            $em = $this->getDoctrine()->getManager();
            $em->remove($application);
            $em->flush();
            return $this->redirectToRoute('fournisseur');
        }
    //routing.yml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    wc_projet_confirmationfr:
        path:     /confirmationfr/{id}
        defaults: { _controller: CentreBundle:Fournisseur:confirmationApplication }
    //index.html.twig
    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
     
    {% extends '::layout/layout.html.twig' %}
     
    {% block title %}List des fournisseurs{% endblock %}
    {% block pageTitle %}{{ ' List des fournisseurs'|upper }}{% endblock %}
     
    {% block breadcrumb %}
        {# this is a expmple how to use a breadcrumb (menu de navigation ) #}
     
        <li>
            <a>List des fournisseurs d'energie</a>
        </li>
    {% endblock %}
     
    {% block body -%}
     
     
         <div class="container">
    		<div class="row">
     
      <div class="span3">
     
      </div>
     
     
                     <section class="span9">
        <div >
            <h3><span class="light">Mes</span> fournisseurs  
               </h3>
        </div>
     <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
     Ajouter un nouveau fournisseur
    </button>
                            <!-- Modal -->
                            <div id="myModal" class="modal fade" role="dialog">
                                <div class="modal-dialog">
     
                                    <!-- Modal content-->
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                                            <h4 class="modal-title">Delete</h4>
                                        </div>
                                        <div class="modal-body">
                                            <p>Voulez vous vraiment supprimer l'application.</p>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
     
                                            </a>
                                        </div>
                                    </div>
     
                                </div>
                            </div>
     <table class="table table-theme table-striped">
            <thead>
                <tr>
     
                    <th>Nom</th>
     
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
            {% for entity in entities %}
                <tr>
                    <td> {{ entity.nomFournisseur }}</td>
     
                    <td>
                    <ul>
                         <button type="button" class="btn btn-info btn-lg" name="delete"  data-toggle="modal" data-target="#myModal">Supprimer</button>
     
                              <a href="{{path('wc_projet_confirmationfr', {'id': (application.id)})}}"> <button type="button" class="btn btn-default">Supprimer</button></a>
     
                    </ul>
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    L'erreur:Variable "application" does not exist.

  5. #5
    Nouveau membre du Club

    Homme Profil pro
    Inscrit en
    Avril 2013
    Messages
    49
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2013
    Messages : 49
    Points : 38
    Points
    38
    Billets dans le blog
    1
    Par défaut
    <a href="{{path('wc_projet_confirmationfr', {'id': (application.id)})}}"> <button type="button" class="btn btn-default">Supprimer</button></a>

    normalement pour vous c entity.id=>application.id

    envoyer une variable à la vue.

Discussions similaires

  1. submit d'un form dans un popup
    Par R1D3M4N dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 05/08/2009, 08h37
  2. Inclure des FORMS dans DESIGNER
    Par Marcel Chabot dans le forum Forms
    Réponses: 1
    Dernier message: 16/01/2008, 10h12
  3. [Form et popup] target d'un form ouvert dans une popup
    Par Flobel dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 19/01/2007, 21h05
  4. [C#] Inclure une form dans une autre
    Par gilles641 dans le forum Windows Forms
    Réponses: 5
    Dernier message: 06/04/2006, 15h45
  5. form dans une popup
    Par amika dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 25/05/2005, 16h06

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