Symfony 和 Doctrine 问题 '在渲染模板期间抛出异常 ( "Notice: Undefined index: equipe" )



我在渲染模板期间的代码有问题。我正在尝试执行一对多双向,但仍然有此错误:

呈现

模板期间引发异常 ("注意:未定义的索引:设备")

我给你我的代码这是我的类"Equipe"反面:

 /**
 * @ORMOneToMany(targetEntity="projetchMauleonBundleEntityEquipe", mappedBy="equipe")
 */
private $services;

这是我的类"服务"拥有方:

/**
 * @ORMManyToOne(targetEntity="projetchMauleonBundleEntityEquipe", inversedBy="services")
 * @ORMJoinColumn(nullable=true)
 */
private $equipe;

这是我的观点:

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

和我的控制器:

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

您在实体Equipe中的targetEntity似乎有问题

 /**
 * @ORMOneToMany(targetEntity="projetchMauleonBundleEntityService", mappedBy="equipe")
 */
private $services;

而不是

 /**
 * @ORMOneToMany(targetEntity="projetchMauleonBundleEntityEquipe", mappedBy="equipe")
 */
private $services;

相关内容

  • 没有找到相关文章

最新更新