简体   繁体   中英

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.

在此输入图像描述

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.

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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM