0

我有一个名为 index 的文件,其中显示了客户查询列表。我想在其中放置多个删除。

我的索引文件列表的代码如下。

 {% block body -%}
<h1>Enquiry list</h1>


<table class="records_list" id="rounded-corner">
    <thead>
        <tr>
    <th>Option</th>
    <th>Id</th>
            <th>Name</th>
            <th>Email</th>
            <th>Subject</th>
            <th>Body</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
    {% for entity in entities %}
        <tr>
    <td><input type="checkbox" name="multiSelect" id="multiSelect[]" value="{{ entity.id }}"></td>
            <td><a href="{{ path('enquiry_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
            <td>{{ entity.name }}</td>
            <td>{{ entity.email }}</td>
            <td>{{ entity.subject }}</td>
            <td>{{ entity.body }}</td>
            <td>

                    <a href="{{ path('enquiry_show', { 'id': entity.id }) }}" title="View"><img src="http://test//bundles/blogger/image/view.png" style="width:30px; height:30px"></a>

                    <a href="{{ path('enquiry_edit', { 'id': entity.id }) }}" title="Edit"> <img src="http://test//bundles/blogger/image/edit.png" style="width:30px; height:30px" > </a>

            </td>
        </tr>
    {% endfor %}
    </tbody>
    <tfooter>

    </tfooter>
</table>

    <ul>
    <li>
        <a href="{{ path('enquiry_new') }}">
            Create a new entry
        </a>
    </li>
</ul>
{% endblock %}

我已经把复选框放在里面了。我想要的是存储所有id的“multiSelect []”的数组值。我正在将它传递给我的控制器。我不知道如何将此数组值作为我的控制器参数传递。所以请帮助我,我想在这里传递它。

<tfooter>

      <a href="{{ path('enquiry_edit', " ")  }}">MultiDelete</a>

</tfooter>    
4

3 回答 3

0

您需要为此使用表格。使用没有表单的输入字段总是一种草率的方式。

于 2013-02-26T08:24:21.177 回答
0

我得到了答案。我已经创建了表单并将请求传递给控制器​​ deleteAction 。

在 deleteAction 方法中

我使用 $request->get('multiSelect'); 获取请求参数 “multiSelect”输入框的名称。

并使用 repositoryclass 对象我已经完成了任务。

感谢您的答复。

于 2013-02-26T09:52:35.963 回答
0

我认为最安全的方法是使用 onclick 生成表单并通过邮寄方式发送的链接。例如:

<a href="{{ path('your_delete_action', { 'id': object.id }) }}" 
   token="{{ token }}"
   data-method="POST"
   object-id ="{{ object.id }}">
   <span class="red"><i class="icon-remove"></i></span>
</a>

然后 onClick 这个链接你生成一个表单并将它发送到你的 deleteAction

// Every link with an attribute data-method
$("#container").on("click", "a[data-method]", function(event){
    event.preventDefault();

    var target = $(event.currentTarget);
    var method = target.attr('data-method');
    var action = target.attr('href');
    var token = target.attr('token');
    var objectId = target.attr('object-id');

    // Create a form on click
    var formulario = $('<form/>', {
        style:  'display:none;',
        method: method,
        action: action
    });

    formulario.appendTo(target);

    formulario.append("<input name='token' value='" + token + "' type='hidden'/>");
    formulario.append("<input name='id' value='" + objectId + "' type='hidden'/>");

    // Do submit
    formulario.submit();

});
于 2013-06-06T15:09:20.820 回答