Symfony2 扩展 table 带有复选框形式
Symfony2 Expaned table with checkboxes form
我有一个 table,其中包含 "ID"、"Category"、"Name" 和 "Action" 等信息。现在我想用复选框改进 table,使用户能够选择多行并一步删除它们。
我的问题:我用表单生成器创建了一个表单:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('id', 'entity', array(
'required' => false,
'class' => 'AppBundle:Task',
'property' => 'id',
'multiple' => true,
'expanded' => true
))
->add('add', 'submit', array('label' => 'Add'));
}
此表单发送到带有 table 的 twig-html,其中包含 table.
的数据
{% if table|length > 0 %}
{{ form_start(addForm) }}
{{ form_errors(addForm) }}
<table class='result' border=1>
<th></th>
<th>ID</th>
<th>Category</th>
<th>Name</th>
<th>Action</th>
{% for item in table %}
<tr>
<td>
{% for entity in addForm.id %}
{% if entity.vars.value == item.id %}
{{ form_widget(entity.vars.form) }}
{% endif %}
{% endfor %}
</td>
<td>{{ item.id }}</td>
<td>{{ item.category }}</td>
<td>{{ item.name }}</td>
<td>{{ item.action }}</td>
</tr>
{% endfor %}
</table>
如您所见,我的解决方案必须在 for 循环中搜索表单项的正确 ID 并放置它们。
我现在的问题:我对这个解决方案感到不满意table - 有没有更简单的方法来显示包含多个列和复选框的 table?
提前致谢
编辑:
还有一个问题是我在选中一些复选框后出现以下错误:
Neither the property "id" nor one of the methods "addId()"/"removeId()", "setId()", "id()", "__set()" or "__call()" exist and have public access in class "AppBundle\Entity\XXXXXX".
也许您应该更好地使用 collection form type rather then the entity type because you will be able to use a custom form and twig template for each record of the database table. In this explanation 您将学习如何删除或添加一行。添加复选框以提供批处理操作将是一个额外的 javascript 解决方案
我有一个 table,其中包含 "ID"、"Category"、"Name" 和 "Action" 等信息。现在我想用复选框改进 table,使用户能够选择多行并一步删除它们。
我的问题:我用表单生成器创建了一个表单:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('id', 'entity', array(
'required' => false,
'class' => 'AppBundle:Task',
'property' => 'id',
'multiple' => true,
'expanded' => true
))
->add('add', 'submit', array('label' => 'Add'));
}
此表单发送到带有 table 的 twig-html,其中包含 table.
的数据{% if table|length > 0 %}
{{ form_start(addForm) }}
{{ form_errors(addForm) }}
<table class='result' border=1>
<th></th>
<th>ID</th>
<th>Category</th>
<th>Name</th>
<th>Action</th>
{% for item in table %}
<tr>
<td>
{% for entity in addForm.id %}
{% if entity.vars.value == item.id %}
{{ form_widget(entity.vars.form) }}
{% endif %}
{% endfor %}
</td>
<td>{{ item.id }}</td>
<td>{{ item.category }}</td>
<td>{{ item.name }}</td>
<td>{{ item.action }}</td>
</tr>
{% endfor %}
</table>
如您所见,我的解决方案必须在 for 循环中搜索表单项的正确 ID 并放置它们。
我现在的问题:我对这个解决方案感到不满意table - 有没有更简单的方法来显示包含多个列和复选框的 table?
提前致谢
编辑:
还有一个问题是我在选中一些复选框后出现以下错误:
Neither the property "id" nor one of the methods "addId()"/"removeId()", "setId()", "id()", "__set()" or "__call()" exist and have public access in class "AppBundle\Entity\XXXXXX".
也许您应该更好地使用 collection form type rather then the entity type because you will be able to use a custom form and twig template for each record of the database table. In this explanation 您将学习如何删除或添加一行。添加复选框以提供批处理操作将是一个额外的 javascript 解决方案