は、ZendのフォームはあなたのHTMLを定義してみましょう、
まずhttps://docs.zendframework.com/zend-form/collections/#creating-fieldsetsを参照してください。 (その逆ではありません)。
たとえば、ParentContainer
という3つのクラスを定義できます。コレクションには、DependentFeature
フィールドセットが含まれています。各DependentFeature
フィールドセットにはSelect要素が含まれ、コレクションにはIndependentFeature
フィールドセットが含まれます。各IndependentFeature
Fielsetには1つのSelect要素が含まれています。 HTMLの結果の
は次のように出てきた:つまり
dependentFeatures[0][dependentFeature]
dependentFeatures[0][independentFeatures][0][independentFeature]
dependentFeatures[0][independentFeatures][1][independentFeature]
dependentFeatures[0][independentFeatures][2][independentFeature]
dependentFeatures[1][dependentFeature]
dependentFeatures[1][independentFeatures][0][independentFeature]
dependentFeatures[1][independentFeatures][1][independentFeature]
dependentFeatures[1][independentFeatures][2][independentFeature]
、要素のコレクションを定義し、巣にそれらを、とZendはあなたのためのHTMLの仕事をやらせます。あなたはこのような何か行うことができますZendのフォーム注釈を使用して
:あなたは注釈を使用していない場合は、私が述べたように、あなたはまだそれを構築することができ
$form = (new AnnotationBuilder())->createForm(ParentContainer::class);
:
/**
* @Annotation\Name("parentContainer")
* @Annotation\Hydrator({"type":"Zend\Hydrator\ClassMethods", "options": {"underscoreSeparatedKeys": false}})
*/
class ParentContainer
{
/**
* @Annotation\ComposedObject({
* "target_object":"DependentFeature",
* "is_collection":"true",
* "options":{"count":2}
* });
*
* @var DependentFeature[]
*/
private $dependentFeatures;
}
/**
* @Annotation\Name("dependentFeature")
* @Annotation\Hydrator({"type":"Zend\Hydrator\ClassMethods", "options": {"underscoreSeparatedKeys": false}})
* @Annotation\Instance("DependentFeature")
* @Annotation\Type("Zend\Form\Fieldset")
*/
class DependentFeature
{
/**
* @Annotation\Type("Zend\Form\Element\Select")
* @Annotation\Options({"label":"Dependent Feature:"})
*/
private $dependentFeature;
/**
*
* @Annotation\ComposedObject({
* "target_object":"IndependentFeature",
* "is_collection":"true",
* "options":{"count":3}
* });
*
* @var IndependentFeature[]
*/
private $independentFeatures;
}
/**
* *
* @Annotation\Name("independentFeature")
* @Annotation\Hydrator({"type":"Zend\Hydrator\ClassMethods", "options": {"underscoreSeparatedKeys": false}})
* @Annotation\Instance("IndependentFeature")
* @Annotation\Type("Zend\Form\Fieldset")
*/
class IndependentFeature
{
/**
* @Annotation\Type("Zend\Form\Element\Number")
* @Annotation\Options({"label":"Independent Feature:"})
*/
private $independentFeature;
}
はそうのようなフォームを作成します。フィールドセットのコレクションをあなたの中に入れ子にすることにより、
要素の名前とネストの正確な方法は、ドメイン要件によって異なります。
何を試しましたか?私たちはあなたのコードを書くつもりはなく、問題が少し絞られるまでは助けません。 – Feathercrown
ZF2でZF2のフィールドセットで使用できるドキュメントは、上記の私の仲間が言ったように、何を試しましたか?まず質問する前に検索しました – Hooli
質問は申し訳ありませんが、zf2コレクションを通じて生成しようとしました。実りあるものは何も起こらない。フィールド 'independent_features'はインデックス依存の 'dependent_features'に直接依存します。つまり、 'independent_features [__ KEY __] []'は 'dependent_features [__ KEY__]'に直接依存します。だから、私はどのようにコレクション要素を通じてこの種のフォームを生成するのか分かりませんでした。私を助けてください。 –