[英]How can I implement a Zend Form entity with an array of elements, using Annotations?
I have a need for a form to record "sets of data", where each set consists of a few numbers. 我需要一个表单来记录“数据集”,其中每个集合由几个数字组成。 User has an option to add additional sets, up to however many is needed. 用户可以选择添加其他设置,但需要很多。 In some cases up to 70 such sets are entered, introducing a need for an array. 在某些情况下,输入多达70个这样的集合,引入了对阵列的需求。
Looking up Zend Form, I liked the approach where a form is created using the Annotations
feature ( https://docs.zendframework.com/zend-form/quick-start/#using-annotations ), since it gives me a neat "object", which I can use for things like saving it directly to the database via ie using Doctrine, and then also retrieving it. 查找Zend Form,我喜欢使用Annotations
功能( https://docs.zendframework.com/zend-form/quick-start/#using-annotations )创建表单的方法,因为它给了我一个整洁的“对象“,我可以用它来直接将它保存到数据库中,即使用Doctrine,然后检索它。
Question 题
How can I define a form in PHP using Zend Form, where the form has expandable set of elements, where I can manage that entity using Doctrine? 如何使用Zend Form在PHP中定义表单,其中表单具有可扩展的元素集,我可以使用Doctrine管理该实体?
Use 采用
/**
* @Annotation\ComposedObject({
* "target_object":"Namespace\Entity\ElementInput",
* "is_collection":"true"
* });
*
* @var ElementInput[]
*/
private $elements;
Later to define the number of elements to show: 稍后定义要显示的元素数量:
$form->get("elements")->setCount($count);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.