Doctrine がインストール/設定された Zend Framework 2 プロジェクトがあります。Zend Form アノテーションをエンティティに直接使用して、エンティティ データを表示/編集するためのフォームを生成しています。問題が発生しています:
ManyToMany 関係で構成されたサブエンティティ (テリトリー) のコレクションを持つエンティティ (ベンダー)。教義の関係は正常に機能しますが、私が追加した zend フォームの注釈
/*
* ...doctrine annotations...
* @Annotation\Type("Zend\Form\Element\Collection")
* @Annotation\Options({"label":"Territory", "target_element": {"type": "\DocurepVendor\Form\TerritoryFieldset"}})
*/
作成した fieldset オブジェクトを作成しますが、フィールド名に配列の名前を付けないでください。(入力はすべて city[] ではなく city という名前です) そのため、更新フォームを送信すると、マッパーは配列を期待しますが、文字列しか見つけられず、失敗します。
これが私のフィールドセットコードです。
TerritoryFieldset.php
namespace DocurepVendor\Form;
use \Zend\Form\Fieldset;
use \Zend\InputFilter\InputFilterProviderInterface;
class TerritoryFieldset extends Fieldset implements InputFilterProviderInterface {
public function __construct($name = null, $options = array()) {
parent::__construct('Locations', $options);
$this->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods())
->setObject(new \DocurepLocation\Entity\Territory());
$this->add(array(
'name' => 'city',
'options' => array(
'label' => 'City'
),
'attributes' => array()
))->add(array(
'name' => 'state',
'options' => array(
'label' => 'State'
),
'attributes' => array(
'required' => 'required'
)
));
}
public function getInputFilterSpecification() {
return array();
}
}
フィールドセットの名前を「city」ではなく「city[]」に設定すると、フィールドセットに教義データが入力されません。
これがサブ要素フィールド セット、親要素の注釈、または完全に別の場所で構成する必要があるものなのか、それとも単にこれを行うことができず、別の方法でこれを実装する必要があるのかはわかりません。誰かが私に正しい方向へのプッシュを与えることができますか?