編集時にデータを入力するために、いくつかのオブジェクトを内部フォームに渡したい次のフォームがあります。
public function __construct( $em, $id ) { $this->_em = $em; } public function buildForm( \Symfony\Component\Form\FormBuilderInterface $builder, array $options ) { $builder->add( 'accessInfo', new AccessInfoType( $this->_em, $options[ 'entities' ][ 'user' ] ) , array( 'attr' => array( 'class' => 'input-medium' ), 「必須」 => false、 'ラベル' => false ) ); $builder->add( 'profileInfo', new ProfileInfoType( $this->_em, $options[ 'entities' ][ 'profile' ] ) , array( 「必須」 => false、 'ラベル' => false ) ); } public function setDefaultOptions( \Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver ) { $resolver->setDefaults( $this->getDefaultOptions( array() ) ); return $resolver->setDefaults( array( ) ); } /** * {@inheritDoc} */ public function getDefaultOptions( 配列 $options ) { $options = 親::getDefaultOptions( $options ); $options[ 'entities' ] = array(); $オプションを返します。 } パブリック関数 getName() { 「ユーザータイプ」を返します。 }
次のコードでインスタンス化します。
$form = $this->createForm( new UserType( $em ), null, array( 'entities' => array( 'user' => $userObj, 'profile' => $profileObj ) ) );
コンストラクターを介して、必要なデータを含むオブジェクトを取得したら、そのオブジェクトをフォームにバインドする方法を知っている人はいますか?
クラス ProfileInfoType は AbstractType を拡張します { プライベート $_em; public function __construct( $em, $dataObj ) { $this->_em = $em; $this->_dataObj = $dataObj; }
ありがとうございます!