【发布时间】:2013-08-05 22:48:09
【问题描述】:
我有一个消息/电子邮件表格,并希望有一个复选框来选择多条消息并使用表格底部的按钮删除它们:
在不使用框架的情况下使用标准 PHP/HTML 非常简单:
<input type="checkbox" name="ids[]" value="510">
<input type="checkbox" name="ids[]" value="1231">
然后在 PHP 中循环遍历已选择的 ID 数组。我正在尝试用 ZF2 实现同样的目标。
ZF2 提供:
FormCollection - is a collection of Fieldsets, which I think is wrong for storing an array of IDs passed.
MultiCheckbox - with the current set of ViewHelpers cannot be extracted using an interator
Checkbox - involves dynamically adding inputs with the ID of the name, but can't be looped through and validated so easily.
如果FormCollection 支持插入元素,我会说这是最好的选择,因为您可以动态添加它们并在发布时循环它们。我想在不久的将来FormCollection 将允许添加元素,取代对MultiCheckbox 和MultiRadio 的需求,因为您可以遍历 FormCollection 并提取各个部分
有没有其他人做过类似的事情,你是怎么做的?
正如我常说的:框架让困难的事情变得简单,让简单的事情变得困难。
【问题讨论】:
-
我正在尝试做同样的事情。你有没有想出一个 Zend 方法来做到这一点?我确定
Collections或MultiSelect缺少一些东西!如果我不同意@crushedGrass 的建议... -
我不相信这是目前可能的 Zend 方式。集合只能包含字段集而不是单个元素。最后,我只是遍历视图中的一个数组,手动打印元素
标签: zend-framework2 zend-form2