PHP ajax呼叫控制器json Bootstrap Modal needHelp

问题描述 投票:0回答:2

我正在做模态,模态显示玩家信息。我们在页面中显示了带有树枝foreach的球员列表。当我单击播放器时,我需要播放器的信息。我尝试了一个简单的引导程序模式,但只有第一个玩家正在工作。我应该使用ajax请求吗?

我这样做:http://pastebin.fr/61334我有一些错误,有人可以帮助我吗?

以及要修改的模板:

<h1 class="monEffectif">Mon effectif</h1>

<div class="globalTable">

<div class="tableLeft">

 {% for trainer in trainers %}
 {% for team in trainer.teams %}

<h2  class="monEffectif">{{ team.name }}</h2>

  {% for category in categories %}

        <table class="table col-10 custom">
        <thead>
            <tr>
                <th>{{ category.Type }} </th> 
                <th>Contact</th>
            </tr>
        </thead>
        <tbody>

        {% for player in category.Person %}

               <tr>
                <td>
                <a href="{{ path('player_showOne', {'id': player.id}) }}" data-toggle="modal" data-target="#dataModal">{{ player.lastname }} {{ player.firstname }}</a>


          <!-- dataModal -->

    <div id="dataModal" class="modal fade">  
        <div class="modal-dialog">  
            <div class="modal-content">  
                <div class="modal-header"> 
                <h4 class="modal-title" id="modal-title">Profil du joueur</h4> 
                    <button type="button" class="close" data-dismiss="modal">&times;</button>  
                </div>  
                <div class="modal-body">  
                <div class="imageModal">
                    <img src="{{ player.picture }} alt="photo du joueur">
                    <p>{{ player.lastname }} {{ player.firstname }}</p>
                </div>

                <div class="blockModal">
                <div class="leftSide">
                    <p>Date de naissance: </p>
                    <p>Nationalité: </p>
                    <p>Adresse: </p>
                    <p>Code postal: </p>
                    <p>Ville: </p>
                    <p>Adresse mail: </p>
                    <p>Numéro portable: </p>
                </div>
                <div class="rightSide">
                    <p>{{ player.birthday|date("d/m/Y") }}</p>
                    <p>{{ player.nationality }}</p>
                    <p>{{ player.address }}</p>
                    <p>{{ player.postal }}</p>
                    <p>{{ player.city }}</p>
                    <p>{{ player.Email }}</p>
                    <p>(+33){{ player.mobilePhone }}</p>
                </div>
                </div>
                </div>  
                <div class="modal-footer">  
                    <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>  
                </div>  
            </div>  
        </div>  
    </div>```
ajax modal-dialog twig
2个回答
0
投票

html中创建唯一ID至关重要,尤其是当您想使用javascript访问它们时。

{% for player in category.Person %}
    <a href="{{ path('player_showOne', {'id': player.id}) }}" data-toggle="modal{{ player.id }}" data-target="#dataModal{{ player.id }}">{{ player.lastname }} {{ player.firstname }}</a>

    <div id="dataModal{{ player.id }}" class="modal fade">  
        ....
    </div>
{% endfor %}

0
投票

没有这样的ajax,效果很好:

    <button type="button" data-toggle="modal" data-target="#dataModal{{ player.id }}">{{ player.lastname }} {{ player.firstname }}</button>

    <div id="dataModal{{ player.id }}" class="modal fade">  
        ....
    </div>
{% endfor %}```

So thank you!
© www.soinside.com 2019 - 2024. All rights reserved.