简体   繁体   中英

Symfony and Doctrine Issue 'An exception has been thrown during the rendering of a template (“Notice: Undefined index: equipe”)

I have a problem with my code during the render of a template. I'm trying to do a One-To-Many Bidirectional but i still have this error :

An exception has been thrown during the rendering of a template ("Notice: Undefined index: equipe")

I give you my codes Here is my class "Equipe" inverse side :

 /**
 * @ORM\OneToMany(targetEntity="projetch\MauleonBundle\Entity\Equipe", mappedBy="equipe")
 */
private $services;

Here is my class "Service" owning side :

/**
 * @ORM\ManyToOne(targetEntity="projetch\MauleonBundle\Entity\Equipe", inversedBy="services")
 * @ORM\JoinColumn(nullable=true)
 */
private $equipe;

This is my view :

 {% block menu %} <body> <div class="row"> <nav class="navbar navbar-default"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <h1> {% if 'projetch_mauleon_presentationSsr' in app.request.attributes.get('_route') %} <a class="navbar-brand" data-type='rd-navbar-brand' href="{{path('projetch_mauleon_accueilSsr')}}" style="font-size: 30px;" >CH <small> Mauléon</small></a> {% elseif 'projetch_mauleon_accueilSsr' in app.request.attributes.get('_route') %} <a class="navbar-brand" data-type='rd-navbar-brand' href="{{path('projetch_mauleon_accueilSsr')}}"style="font-size: 30px;" >CH <small> Mauléon</small></a> {% else %} <a class="navbar-brand" data-type='rd-navbar-brand' href="{{path('projetch_mauleon_accueilEhpad')}}"style="font-size: 30px;" >CH <small> Mauléon</small></a> {% endif %} </h1> </div> <!-- Collect the nav links, forms, and other content for toggling --> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <ul class="nav navbar-nav sf-menu"> <li {% if 'projetch_mauleon_presentationEhpad' in app.request.attributes.get('_route') %} class="active" {% endif %} > <a href="{{path('projetch_mauleon_presentationEhpad')}}">Bienvenue</a> </li> <li class="dropdown" data-dropdown="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Notre organisation <b class="caret"></b></a> <ul class="dropdown-menu"> <li><a href="{{path('projetch_mauleon_presentationEhpad')}}">Présentation</a></li> <li><a href="{{path('projetch_mauleon_historique')}}">Historique</a></li> <li><a href="{{path('projetch_mauleon_gouvernance')}}">Gouvernance</a></li> <li><a href="{{path('projetch_mauleon_actualitesEhpad')}}">Nos actus</a></li> <li><a href="{{path('projetch_mauleon_projet')}}">Orientations et projets</a></li> </ul> </li> <li class="dropdown"> <a tabindex="0" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" data-submenu> Nos équipes <b class="caret"></b></a> <ul class="dropdown-menu multi level" id="MainMenu" > {% for equipeCourante in tabEquipes %} {% if equipeCourante.services is empty %} <li> <a id="fontDrop" href="{{path('site_equipe', {'id':equipeCourante.id})}}"> {{equipeCourante.nom}} </a></li> {% else %} <li class="dropdown-submenu"> <a id="fontDrop" href="#" class="dropdown-toggle" data-toggle="dropdown"> {{equipeCourante.nom}} </a> <ul class="dropdown-menu "> {% for service in equipeCourante.services %} <li><a id="fontDrop" href="#"> {{ service.nom }} </a></li> {% endfor %} </ul> </li> {% endif %} {% endfor %} </ul> </li> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Votre accueil <b class="caret"></b></a> <ul class="dropdown-menu"> <li> <a href="{{path('projetch_mauleon_admissionEhpad')}}">Votre admission</a> </li> <li> <a href="{{path('projetch_mauleon_sejour')}}">Votre séjour</a> </li> <li> <a href="{{path('projetch_mauleon_documentsEhpad')}}">Vos documents</a> </li> <li> <a href="{{path('projetch_mauleon_questionnaire')}}">Votre avis nous interesse</a> </li> </ul> </li> <li id="cht" {% if 'projetch_mauleon_recrutementEhpad' in app.request.attributes.get('_route') %} class="active" {% endif %} > <a href="{{path('projetch_mauleon_recrutementEhpad')}}">Espace <br/> Recrutement</a> </li> <li {% if 'projetch_mauleon_contactEhpad' in app.request.attributes.get('_route') %} class="active" {% endif %}> <a href="{{path('projetch_mauleon_contactEhpad')}}">Contact</a> </li> <li> {% if 'projetch_mauleon_accueilSsr' in app.request.attributes.get('_route') %} <a href="{{path('projetch_mauleon_accueilEhpad')}}"> EHPAD </a></li> {% else %} <li> <a href="{{path('projetch_mauleon_accueilSsr')}}">SSR</a> </li> {% endif %} </ul> </div> </div> </nav> </div> </body> {% endblock %} 

and my controler :

    public function menuAction()
{
    $em=$this->getDoctrine()->getManager();
    $repositoryEquipe = $em->getRepository('projetchMauleonBundle:Equipe');
    $tabEquipes = $repositoryEquipe->findAll();

    return $this->render('projetchMauleonBundle:Mauleon:menu2.html.twig', array('tabEquipes'=>$tabEquipes));

}

Your targetEntity in your Entity Equipe seems wrong

 /**
 * @ORM\OneToMany(targetEntity="projetch\MauleonBundle\Entity\Service", mappedBy="equipe")
 */
private $services;

instead of

 /**
 * @ORM\OneToMany(targetEntity="projetch\MauleonBundle\Entity\Equipe", mappedBy="equipe")
 */
private $services;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM