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)

图片转代码服务由CSDN问答提供 功能建议

我正在尝试处理一些与同一个表实体绑定的字段集,并嵌套在另一个表实体中 。 例如:

模型:

 表格构建
-&gt; 名\正&GT; 说明\正&GT; 街道名称
-&gt; 街道号码
-&gt; 看门人的电话
-&gt; 等级计数
-&gt; 高度\正&GT; 构造年份
   
 
 

所有这些字段都在一个表中,但我想使用倍数字段集,例如这样:

  descriptionBlgFieldset 
-&gt; name 
-&gt; description 
 
AddressBlgFieldset 
-&gt; street Name 
-&gt; street Number 
-&gt; 看门人的电话
 
FeaturesBlgFieldset 
-&gt; 等级计数
-&gt; 高度\正&GT; 构建年份
   
 
 

然后我想在其他字段集中混合它们,例如地址的描述,或者特征的描述,或者所有这些。 我以为这是和平的蛋糕,但我不知道如何处理绑定:

  echo $ form-&gt; get('building') - &gt; get  ('地址') - &gt; get('streetNumber)
   
 
 

给我:

 &lt; input  name =“building [addresse] [streetNumber]”/&gt; 
   
 
 

但必须是:

   &lt; input name =“building [streetNumber]”/&gt; 
   
 
 

我在考虑“set_as_base_fieldset”选项,但它只在我忙的时候才有效 表单对象中的字段集,而不是字段集中的字段集。

我怎么能这样做? (我希望这很清楚)

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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();
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题