Zend:ViewScript 装饰器和数组表示法 [英] Zend: ViewScript decorator and array notation

查看:31
本文介绍了Zend:ViewScript 装饰器和数组表示法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复选框矩阵,我将其放在表格中.我需要将这个矩阵拉成多种形式,有时在一种形式上多次,所以我将它设置为子形式.

I have a matrix of checkboxes which I am laying out in a table. I need to pull this matrix into a number of forms, and sometimes multiple times on one form, so I have set it up as a subform.

经过大量研究和深思熟虑,我决定装饰子窗体的最佳方法是使用 viewScript 装饰器.将子表单添加到表单的代码如下所示:

After much research and deliberation, I decided the best way to decorate the subform was using the viewScript decorator. The code for adding the subform to the form looks something like this:

$this->addSubForm(new Test_Form_Connection_Config_Base(), 'user');
$this->user->setDecorators(array(
    array('viewScript', array('viewScript' => '_forms/userConfig.phtml')),
          'Description',
          'FieldSet',
        ));

在大多数情况下,这工作正常,但我遇到的一个问题是我无法使用数组表示法.显然,当我在特定表单上多次包含矩阵时,这会成为一个问题.

For the most part this works fine however the one problem I have is that I can't get array notation to work. Obviously this becomes a problem when I include the matrix more than once on a particular form.

我尝试使用 setIsArray(true) 但这没有效果.似乎我需要运行 FormElements 装饰器来获取数组表示法,但这会在页面上给我一组重复的字段(由 FormElements 渲染一次,由 viewScript 渲染一次).

I tried using setIsArray(true) however this had no effefct. It seems that I need to run the FormElements decorator to get the array notation, but this then gives me a duplicate set of fields on the page (rendered once by FormElements, and once by viewScript).

我可以手动构造每个元素的名称以反映数组表示法,但这似乎很远.我还缺少其他选项吗?

I could manually construct the name of each element to reflect array notation, but this seems like the long way around. Are there any other options that I'm missing?

谢谢...!

推荐答案

在使用 ViewScript 装饰器之前,您应该始终使用 PrepareElements 装饰器来规范化名称.

Before using the ViewScript decorator, you should always use the PrepareElements decorator to normalize names.

参见 http://framework.zend.com/manual/en/zend.form.standardDecorators.html#zend.form.standardDecorators.prepareElements

这篇关于Zend:ViewScript 装饰器和数组表示法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆