Zend: ViewScript decorator and array notation

强颜欢笑 提交于 2019-12-20 03:52:10

问题


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.

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.

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?

Thanks...!


回答1:


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

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



来源:https://stackoverflow.com/questions/7155047/zend-viewscript-decorator-and-array-notation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!