我有以下表单,我想将一些对象传递给内部表单,以便在编辑时用数据填充它们:
公共函数 __construct($em, $id)
{
$this->_em = $em;
}
公共函数 buildForm(\Symfony\Component\Form\FormBuilderInterface $builder, array $options)
{
$builder->add( 'accessInfo', new AccessInfoType( $this->_em, $options[ 'entities' ][ 'user' ] ) , array(
'attr' => 数组('class' => 'input-medium' ),
'必需' => 假,
'标签' => 假
)
);
$builder->add( 'profileInfo', new ProfileInfoType( $this->_em, $options[ 'entities' ][ 'profile' ] ) , array(
'必需' => 假,
'标签' => 假
)
);
}
公共函数 setDefaultOptions( \Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver )
{
$resolver->setDefaults($this->getDefaultOptions(array()));
返回 $resolver->setDefaults(array());
}
/**
* {@inheritDoc}
*/
公共函数 getDefaultOptions( 数组 $options )
{
$options = parent::getDefaultOptions( $options );
$options['entities'] = array();
返回$选项;
}
公共函数 getName()
{
返回“用户类型”;
}
我用以下代码实例化:
$form = $this->createForm( new UserType( $em ), null, array( 'entities' => array( 'user' => $userObj, 'profile' => $profileObj ) ) );
一旦我通过构造函数获得包含所需数据的对象,有人知道我如何将该对象绑定到表单吗?
类 ProfileInfoType 扩展 AbstractType
{
私人 $_em;
公共函数 __construct($em, $dataObj)
{
$this->_em = $em;
$this->_dataObj = $dataObj;
}
先谢谢了!