Php 将表单嵌入链接到Symfony2中实体的另一个表单
我需要将一个表单嵌入到另一个表单中,我的操作如下:Php 将表单嵌入链接到Symfony2中实体的另一个表单,php,forms,symfony,symfony-forms,Php,Forms,Symfony,Symfony Forms,我需要将一个表单嵌入到另一个表单中,我的操作如下: use Symfony\Component\Form\AbstractType, Symfony\Component\Form\FormBuilderInterface, Symfony\Component\OptionsResolver\OptionsResolverInterface, Common\CommonBundle\Form\AddressExtraInfoType; class StandardAddr
use Symfony\Component\Form\AbstractType,
Symfony\Component\Form\FormBuilderInterface,
Symfony\Component\OptionsResolver\OptionsResolverInterface,
Common\CommonBundle\Form\AddressExtraInfoType;
class StandardAddressType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('country', 'entity', array( ... ))
->add('state', 'entity', array( ... ))
->add('city', 'entity', array( ... ))
->add('extra_info', new AddressExtraInfoType());
}
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$resolver->setDefaults(array(
'data_class' => 'Common\CommonBundle\Entity\StandardAddress'
));
}
public function getName() {
return 'common_commonbundle_standard_address';
}
}
由于主表单需要附加到'data\u class'=>'Common\CommonBundle\Entity\standarddress'
上,因此当我尝试获取表单时,出现以下错误:
Neither the property "extra_info" nor one of the methods "getExtraInfo()", "isExtraInfo()", "hasExtraInfo()", "__get()" exist and have public access in class "Common\CommonBundle\Entity\StandardAddress"
我怎样才能解决这个问题?如何将第二个表单嵌入到第一个表单中而不获取此eror?尝试以下方法:
$builder->add('extra_info', new AddressExtraInfoType(), array('mapped' => false));
类Common\CommonBundle\Entity\standarddress中没有字段额外信息,因此必须使用表单类型中的非映射字段。最后,在再次阅读我的代码后,我找到了错误所在。在我的
AddressExtraInfo
实体中,我有address\u extra\u info
,当然将其更改为extra\u info
解决了这个问题,无论如何,谢谢您的回复