如何在 Zend 中访问输入表单动态创建表单

How get access to input form dynamic create form in Zend

我尝试为图书列表构建表单。我想让 make 更新每一行中的每个数量位置。我以为我可以用一个字段创建动态表单,比如数量。

$zendFormUpdate = new Zend_Form;
for ($i = 0; $i < 4; $i++){
    $quantity[$i] = $this->addElement('text','quantity'.$i,[
        'required' => false,
     ]);
}
$this->view->forms = ['formupdate' => $zendFormUpdate];

现在我想问你,我怎样才能得到这些字段? 我正在使用下面的代码,但我什么也得不到

<html>
    <body>
        <p>
        <form>
            <?php for ($i = 0; $i < 4; $i++){ ?>
            <?php echo $this->forms['formupdate']->quantity.$i; ?>
            <?php } ?>
        </form>
        </p>
    </body>
</html>

尝试:

// note the s after ->form, as well
$this->forms['formupdate']->getElement( 'quantity' . $i );

但是由于这是一个印刷错误,因此:

$this->forms['formupdate']->{ 'quantity' . $i };

应该也可以。我忘了你也可以用这种方式访问​​ Zend_Form 元素。