1
我有以下問題。我想創建一個適用於兩個實體的表單。我有以下實體:第一個實體是用戶實體,並且它與第二個實體(與實體「BIP」相關的列bip)有關聯。 現在我下面的代碼:一種形式的多個實體
BIPType.php:
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();
}
不幸的是,錯誤發生
Catchable Fatal Error: Argument 1 passed to UserBundle\Entity\User::setBip() must be an instance of AppBundle\Entity\Bip, array given, called in /home/spake/php/gryf/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php on line 556 and defined
怎麼辦,我的朋友?謝謝你的建議。
非常感謝你,這個作品! –