dongronge3732 2014-08-20 10:33
浏览 37
已采纳

更新表格symfony2中的表格行

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条回答 默认 最新

  • download2014711 2014-08-20 14:15
    关注

    You need to define your variable $request like this:

    $request = $this->getRequest();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号