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

时间:2021-10-05 06:48:43

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.

我在想什么“set_as_base_fieldset”选项,但它只在我在表单对象中而不是在字段集中使用字段集时才起作用。

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

我怎么能这样做? (我希望这很明显)

1 个解决方案

#1


0  

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:

如果你想构建[streetNumber],那么你不想使用Fieldset。这就是它的全部内容。 Zend \ Form \ Fieldset是一个元素,它封装了一组独立/自己的对象属性。例如:

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

在这种情况下,您将拥有一个AddressFieldset。但这不是你想要的。我假设您只将其划分为字段集以对默认呈现产生影响。这是对Zend \ Form \ Fieldset的误用。你只需要像表单一样呈现你的表单

echo $this->form()->openTag($form);
echo "<fieldset>\n";
echo "    <legend>Address</legend>\n";
echo $this->formRow($form->get('streetName'));
echo $this->formRow($form->get('streetNuber'));
echo "</fieldset>\n";
echo "<fieldset>\n";
echo "    <legend>Features</legend>\n";
echo $this->formRow($form->get('levelCount'));
echo $this->formRow($form->get('height'));
echo "</fieldset>\n";
echo $this->form()->closeTag();

#1


0  

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:

如果你想构建[streetNumber],那么你不想使用Fieldset。这就是它的全部内容。 Zend \ Form \ Fieldset是一个元素,它封装了一组独立/自己的对象属性。例如:

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

在这种情况下,您将拥有一个AddressFieldset。但这不是你想要的。我假设您只将其划分为字段集以对默认呈现产生影响。这是对Zend \ Form \ Fieldset的误用。你只需要像表单一样呈现你的表单

echo $this->form()->openTag($form);
echo "<fieldset>\n";
echo "    <legend>Address</legend>\n";
echo $this->formRow($form->get('streetName'));
echo $this->formRow($form->get('streetNuber'));
echo "</fieldset>\n";
echo "<fieldset>\n";
echo "    <legend>Features</legend>\n";
echo $this->formRow($form->get('levelCount'));
echo $this->formRow($form->get('height'));
echo "</fieldset>\n";
echo $this->form()->closeTag();