du127953 2014-04-16 07:37
浏览 28
已采纳

ZF2:嵌套字段集; 结合和水合作用

I'm trying to deal with some fieldsets witch are bind with the same table entity, and nested in some other one. Exemple:

Model:

Table Building
-> Name
-> Description
-> street name
-> street Number
-> consierge's phone
-> level count
-> height
-> Year of construction

All this fields are in one table but i whant to use multiples fieldset, like this for exemple:

descriptionBlgFieldset
->name
->description

AddressBlgFieldset
->street Name
->street Number
-> consierge's phone

FeaturesBlgFieldset
-> level count
-> height
-> Year of construction

Then i whant to blend those in some other field set, for exemple description with address, or description with features, or all of them. I was thinking this was peace of cake, but i dont know how to deal for the binding:

echo $form->get('building')->get('address')->get('streetNumber)

give me:

<input name="building[addresse][streetNumber]" />

But it's must be:

<input name="building[streetNumber]" />

I what thinking about the "set_as_base_fieldset" option, but it's only work when I'm hadding a fieldset in a form object, not in a fieldset.

How could i do that? (i hope this whas clear enought)

  • 写回答

1条回答 默认 最新

  • douya1974 2014-04-16 08:14
    关注

    If you want building[streetNumber] then you don't want to use a Fieldset. That's really all there is to it. A Zend\Form\Fieldset is an Element that encapsulates a set of properties that are standalone / their own object. For example:

    Table Buildings
    - id
    - attr1
    - addr_id
    
    Table Addresses
    - id
    - name
    - nr
    

    In this case you'd have an AddressFieldset. But this isn't what you want. I assume you only divided this into fieldsets to have an impact on the default rendering. This is a mis-use of Zend\Form\Fieldset. You simply will have to render your form differently like

    echo $this->form()->openTag($form);
    echo "<fieldset>
    ";
    echo "    <legend>Address</legend>
    ";
    echo $this->formRow($form->get('streetName'));
    echo $this->formRow($form->get('streetNuber'));
    echo "</fieldset>
    ";
    echo "<fieldset>
    ";
    echo "    <legend>Features</legend>
    ";
    echo $this->formRow($form->get('levelCount'));
    echo $this->formRow($form->get('height'));
    echo "</fieldset>
    ";
    echo $this->form()->closeTag();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?