0

我想问一下通过另一个不同包中的实体形式在一个包中添加一个实体。

我觉得这在 symfony 中是不可能的,因为当我尝试它时,我得到了一个警告。

Catchable Fatal Error: Argument 1 passed to xxx\twoBundle\Entity\entity1::setUser() must be an instance of xxx\oneBundle\Entity\User, array given, called in C:\wamp\www\Symfony\vendor\symfony\symfony\src\Symfony\Component\Form\Util\PropertyPath.php on line 538 and defined in C:\wamp\www\Symfony\src\xxx\twoBundle\Entity\entity1.php line 446 

有任何想法吗???

4

1 回答 1

0

好的,为您的实体创建一个表单类型并设置 dataClass:

class MySecondEntityFormType {

public function buildForm(FormBuilderInterface $builder, array $options)
{        
    $builder->add('someField');
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'data_class' => 'XXX\TwoBundle\Entity\MySecondEntity',
    ));
}

现在在主窗体中添加新创建的窗体:

public function buildForm(FormBuilderInterface $builder, array $options)
{        
    ...
    $builder->add('mySecondEntity', new MySecondEntityFormType());
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    $resolver->setDefaults(array(
        'compound' => true
    ));
}
于 2013-05-02T10:37:27.490 回答