0

I want to update a row of my tables .

When the user click on the icone of modify i want to redirect him in form that already get the information of row selected.

in the controller :

public function modifyBuAction($id){



    $entite=$this->get('entite.entiteservice')->findEntiteById($id);

    $form = $this->get('form.factory')->create(new BuType(), $entite); // On bind l'objet Entite à notre formulaire BuType

    if ('POST' == $request->getMethod()) { // Si on a posté le formulaire
        $form->bind($request);
        if ($form->isValid()) { // Si le formulaire est valide

            $this->get('entite.entiteservice')->saveEntite($entite); // On utilise notre Manager pour gérer la sauvegarde de l'objet Conge

            return $this->render('acmeBundle:admin:index.html.twig');
        }

    }

    return $this->render("acmeBundle:admin:modifyBu.html.twig",array("entite"=>$entite));

}

in the twig :

 <form action="{{ path('modify_bu') }}" method="post" id="bu_form" >


</br>

                <table class="form">

                      <tr>
                        <td class="col1">
                            <label>
                                {{ form_errors(form.nomEntite) }}
                                {{ form_label(form.nomEntite, 'Nom entite:') }} 
                            </label>
                        </td>
                        <td class="col2">
                            {{ form_widget(form.nomEntite) }}
                        </td>
                      </tr>
                      <tr>
                        <td class="col1">
                            <label>
                                {{ form_errors(form.nomAgence) }}
                                {{ form_label(form.nomAgence, 'Nom agence:') }} 
                            </label>
                        </td>
                        <td class="col2">
                            {{ form_widget(form.nomAgence) }}
                        </td>
                    </tr>
                    <tr>
                        <td class="col1">
                            <label>
                                {{ form_errors(form.entiteAbrev) }}
                                {{ form_label(form.entiteAbrev, 'abreviation entite:') }}   
                            </label>
                        </td>
                        <td class="col2">
                            {{ form_widget(form.entiteAbrev) }}
                        </td>
                    </tr>
                    <tr>
                        <td class="col1">
                            <label>
                                {{ form_errors(form.entiteNiveau) }}
                                {{ form_label(form.entiteNiveau, 'Niveau abreviation:') }}  
                            </label>
                        </td>
                        <td class="col2">
                            {{ form_widget(form.entiteNiveau) }}
                        </td>
                   </tr>



</table>

in the BuType :

 public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('nomEntite')
        ->add('nomAgence')
        ->add('entiteAbrev')
        ->add('entiteNiveau');

}

i get this in the twig of table:

  <table class="data display datatable" id="example">
                <thead>
                    <tr>
                        <th>Nom Entite</th>
                        <th>Nom Agence</th>
                        <th>Abr&eacute;viation Entite</th>
                        <th>Niveau Entite</th>
                        <th>Modifier/Supprimer</th>


                    </tr>
                </thead>
                <tbody>


                     {% for entite in liste %}




                            <tr class="odd gradeX">

                                     <td> {{ entite.nom_entite  }} </td> 
                                     <td> {{ entite.nom_agence  }} </td> 
                                     <td> {{ entite.entite_abrev }} </td>
                                     <td> {{ entite.entite_niveau  }} </td> 
                                     <td>
                                        <a  href={{ path('modify_bu', {'id': entite.id}) }}><img src="{{ asset('bundles/acme/img/modifier.png')}}" width="20" height="20"  /></a>
                                        <a  href={{ path('delete_bu', {'id': entite.id}) }} onclick="myFunction()"><img src="{{ asset('bundles/acme/img/delete.png')}}" width="20" height="20" /></a>
                                     </td>
                            </tr>

                    {% endfor %}

when i clik on the icone of modification i want to get a form with the information of row selected

any help please?

1 Answer 1

1

You need to define your variable $request like this:

$request = $this->getRequest();
Sign up to request clarification or add additional context in comments.

5 Comments

now i have another exception : An exception has been thrown during the rendering of a template ("Some mandatory parameters are missing ("id") to generate a URL for route "modify_bu"."). i want when i get the formType i get in the information of row selected how can i do it?
You are missing a setting in your path in your form, it is : {{ path('modify_bu', { 'id' : yourId }) }}
In addition, you can look to the paramConverter to simplify your controller : symfony.com/fr/doc/current/bundles/SensioFrameworkExtraBundle/…
Le Menach Florian i I put the path in the twig of table, i updated my quastion
Good, in your controller you select your entity with you id. Now, you must get your form in your view : return $this->render("acmeBundle:admin:modifyBu.html.twig",array( "entite" => $entite, "form" => $form->createView() )); And in your twig template you can show the form link this : {{ form_widget(form) }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.