我正在尝试访问我的for循环之外的用户ID
表
{% set userid = '' %}
<table class="display dataTable" id="manageusertable" cellspacing="0" width="100%">
<thead>
<tr>
<th>Image</th>
<th>Login</th>
<th>Nom / Prenom</th>
<th>Email</th>
<th>Activé</th>
<th>Actions</th>
</tr>
</thead>
<tfoot>
</tfoot>
<tbody>
{% for user in users %}
{% set userid = user.id %}
<tr class="getid">
<td>{{ user.UserImage }}</td>
<td>{{ user.username }}</td>
<td>{{ user.UserLastname }} / {{ user.UserFirstName }}
</td>
<td>{{ user.email }}</td>
{% if user.enabled == 1 %}
<td><i class="fa fa-check" aria-hidden="true"></i></td>
{% else %}
<td><i class="fa fa-times" aria-hidden="true"></i></td>
{% endif %}
<td>
<i class="fa fa-search" aria-hidden="true"></i>
<button type="button" class="btn btn-add btn-sm" data-
toggle="modal" data-target="#update"><i class="fa fa-
pencil"></i></button>
<button type="button" class="deleteuser btn btn-danger
btn-sm" data-toggle="modal" data-target="#deleteuser"><i
class="fa fa-trash-o"></i> </button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
当点击按钮数据模型= #dutore时,模态div(外部循环)
<div class="modal fade" id="deleteuser" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header modal-header-primary">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3><i class="fa fa-user m-r-5"></i> Delete User</h3>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<form class="form-horizontal">
<fieldset>
<div class="col-md-12 form-group user-form-group">
<label class="control-label">Delete User</label>
<div class="pull-right">
<button type="button" class="btn btn-danger btn-sm">NO</button>
<button " class="btn btn-add btn-sm"><a style="color:#fff;" href="{{ path('lemon_user_deleteuser', {'id': userid}) }}">YES</a></button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger pull-left" data-dismiss="modal">Close</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
这条线
<button " class="btn btn-add btn-sm"><a style="color:#fff;" href="{{ path('lemon_user_deleteuser', {'id': userid}) }}">YES</a></button>
总是返回最后一个id(如果我的数据库中有15个用户,则为15)无论单击按钮哪一行
我知道如何使用jquery / ajax和从头开始执行此操作但是因为我对symfony / twig的新手有点丢失了
答案 0 :(得分:0)
在你的情况下,你必须使用整个id组成一个数组,例如
PdfFontEncoding.Unicode
然后为每个删除按钮和路径设置重做“for循环”