Php 一种形式的多个实体
我有以下问题。我想创建一个在两个实体上工作的表单。我有以下实体:第一个实体是用户实体,它与第二个实体有关联(bip列与实体“bip”相关)。 现在我有以下代码: BIPType.php:Php 一种形式的多个实体,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,我有以下问题。我想创建一个在两个实体上工作的表单。我有以下实体:第一个实体是用户实体,它与第二个实体有关联(bip列与实体“bip”相关)。 现在我有以下代码: BIPType.php: public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('name'); } public function getDefaultOptions(array $opt
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name');
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'AppBundle\Entity\Bip',
);
}
和UserType.php:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$biptype = new BIPType();
$builder->add('bip', $biptype);
}
public function getParent()
{
return 'FOS\UserBundle\Form\Type\RegistrationFormType';
// Or for Symfony < 2.8
// return 'fos_user_registration';
}
public function getBlockPrefix()
{
return 'app_user_registration';
}
// For Symfony 2.x
public function getName()
{
return $this->getBlockPrefix();
}
public function buildForm(formbuilder接口$builder,数组$options)
{
$biptype=新的biptype();
$builder->add('bip',$biptype);
}
公共函数getParent()
{
返回'FOS\UserBundle\Form\Type\RegistrationFormType';
//或对于Symfony<2.8
//返回“fos_用户注册”;
}
公共函数getBlockPrefix()
{
返回“应用程序用户注册”;
}
//对于Symfony 2.x
公共函数getName()
{
返回$this->getBlockPrefix();
}
不幸的是,发生了错误
可捕获的致命错误:传递给UserBundle\Entity\User::setBip()的参数1必须是AppBundle\Entity\Bip的实例,给定数组,在第556行的/home/spake/php/gryf/vendor/symfony/symfony/src/symfony/Component/PropertyAccess/PropertyAccessor.php中调用并定义
朋友们,该怎么办?谢谢您的建议。您需要像下面这样声明该表单类的实体类:
$builder->add('bip', new BipType(), array(
'data_class' => 'namespace/to/BipEntity'
));