恢复ID表单数据库

时间:2013-06-06 08:40:30

标签: php symfony doctrine-orm

我在从数据库中恢复对象时遇到一个小问题,问题是我恢复了除了我需要在url中传递的ID以外的所有内容,我的对象存储在从一个继承自一个抽象的实体派生的表中上课,你遇到过这样的问题吗?

Controller.php这样:

   // lister toute les affaires:  
      public function listerAction($page)
      {
        if( $page < 1 )
                {
                  // On déclenche une exception NotFoundHttpException
                  // Cela va afficher la page d'erreur 404 
                  throw $this->createNotFoundException('Page inexistante (page = '.$page.')');
                }

            $form = $this->container->get('form.factory')->create(new ContactRechercheForm());  
            $affairesPC = $this->getDoctrine()
                         ->getManager()
                         ->getRepository('AffaireBundle:AffairePompeChaleur')
                         ->findAll();
             $affaires = $this->getDoctrine()
                         ->getManager()
                         ->getRepository('AffaireBundle:Affaire')
                         ->findAll();
            $affairesPS = $this->getDoctrine()
                         ->getManager()
                         ->getRepository('AffaireBundle:AffairePanneauSolaire')
                         ->findAll(); 

     return $this->container->get('templating')->renderResponse('AffaireBundle:Affaires:affaires.html.twig',array(
            'affairesPS' =>  $affairesPS, 'affairesPC' => $affairesPC,'form' => $form->createView()));

      }

affaires.html.twig

    {# src/Crm/AffaireBundle/Resources/views/Affaires/affaires.html.twig #}

{% extends "AffaireBundle::layout.html.twig" %}

{% block title %}
  Accueil - {{ parent() }}
{% endblock %}

{% block Affaire_body %}

<form id="form_recherche" action="{{ path('affaire_rechercher_affaire') }}" method="post">
    <table style="border-collapse:separate;border-spacing: 10px 8px;">
          <tr>

                <td>

                {{ form_widget(form.motcle)  }}
                </td>   
                <td><input type="submit" value="Rechercher" class="btn btn-small" style="margin-top: -8px;"/></td>
          </tr>
        </table> 

</form>

<div class="loading"></div>  
<div id="resultats_recherche"> 
    {% include 'AffaireBundle:Affaires:liste.html.twig' with {'affairesPC' : affairesPC} %}
</div>  

<script>
$(".loading").hide();
$("#form_recherche").submit(function(){ 
    $(".loading").show();
    var motcle = $("#contactrecherche_motcle").val();
    var DATA = 'motcle=' + motcle;
    $.ajax({
        type: "POST",
        url: "{{ path('affaire_rechercher_affaire')}}",
        data: DATA,
        cache: false,
        success: function(data){
           $('#resultats_recherche').html(data);
           $(".loading").hide();
        }
    });    
    return false;
});
</script>

{% endblock %}

liste.html.twig:

    <h4>Liste des Affaires <a href="{{ path('affaire_afficherformulaire_affaire') }}" class="btn btn-primary" style="float: right;">ajouter affaire</a></h4>
<br>
<div id="resultats_recherche"> 
                                 <form id="mainform" action="">

                <table border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
                <thead>
                                <tr>
                    <!--<th class="table-header-check"><a id="toggle-all" ></a> </th>-->
                                        <th class="table-header-repeat line-left minwidth-1"><a href="">Titre</a>   </th>
                                        <th class="table-header-repeat line-left minwidth-1"><a href="">Relative à</a> </th>
                    <th class="table-header-repeat line-left minwidth-1"><a href="">Phase </a></th>
                                        <th class="table-header-repeat line-left minwidth-1"><a href="">Type </a></th>
                    <th class="table-header-repeat line-left"><a href="">Description</a></th>

                    <th class="table-header-options line-left"><a href="">Options</a></th>
                </tr>
                                 </thead>


                                 {% for affairePC in affairesPC%}
                                 <tr>
                    <!--<td><input  type="checkbox"/></td>-->

                    <td><a href="{{ path('affaire_voir_affaire', { 'id': affairePC.id }) }}">  {{ affairePC.id }} </td>

                                        {#<td><a href="{{ path('contact_voir_individu', { 'id': affaire.contact.id }) }}">  {{ affaire.contact.nom }} </td>#}


                                        {#<td>{{affaire.phaseAffaire.phase }}</td>#}
                                       {# <td>{{affaire.typeAffaire.type }}</td>#}
                    <td>{{affairePC.description }}</td>


                    <td class="options-width">
                                        <a href="{{ path('affaire_modifier_affaire', { 'id': affairePC.id }) }}" class="icon-1 info-tooltip" title="modifier"></a>  
                                        <a href="{{ path('affaire_voir_affaire', { 'id': affairePC.id }) }}" title="supprimer" class="icon-2 info-tooltip"></a>


                <!--    <a href="" title="supprimer" class="icon-2 info-tooltip"></a>
                                        <a href="" title="Edit" class="icon-3 info-tooltip"></a>
                    <a href="" title="Edit" class="icon-4 info-tooltip"></a>
                    <a href="" title="Edit" class="icon-5 info-tooltip"></a> -->
                    </td>
                </tr>




                {% endfor %}
                                 {% for affairePS in affairesPS%}
                                 <tr>
                    <!--<td><input  type="checkbox"/></td>-->

                    <td><a href="{{ path('affaire_voir_affaire', { 'id': affairePS.id }) }}">  {{ affairePS.nom }} </td>

                                        <td><a href="{{ path('contact_voir_individu', { 'id': affairePS.contact.id }) }}">  {{ affairePS.contact.nom }} </td>


                                        <td>{{affairePS.phaseAffaire.phase }}</td>
                                        <td>{{affairePS.typeAffaire.type }}</td>
                    <td>{{affairePS.description }}</td>


                    <td class="options-width">
                                        <a href="{{ path('affaire_modifier_affaire', { 'id': affairePS.id }) }}" class="icon-1 info-tooltip" title="modifier"></a>  
                                        <a href="{{ path('affaire_voir_affaire', { 'id': affairePS.id }) }}" title="supprimer" class="icon-2 info-tooltip"></a>


                <!--    <a href="" title="supprimer" class="icon-2 info-tooltip"></a>
                                        <a href="" title="Edit" class="icon-3 info-tooltip"></a>
                    <a href="" title="Edit" class="icon-4 info-tooltip"></a>
                    <a href="" title="Edit" class="icon-5 info-tooltip"></a> -->
                    </td>
                </tr>




                {% endfor %}
                </table>




                </form>

    </div>

0 个答案:

没有答案
相关问题