更新表单symfony2中的表行


update row of table in forms symfony2

我想更新我的表中的一行。

当用户点击图标的修改,我想重定向他的形式,已经得到行选择的信息。

控制器

:

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));
}

在树枝上:

 <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>

中的BuType:

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

我得到这个在表的小枝:

  <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 %}

当我点击修改图标时,我想要得到一个包含所选行信息的表单

请帮忙好吗?

您需要像这样定义变量$request:

$request = $this->getRequest();