普通网友 2013-05-02 09:59
浏览 36

通过表单symfony2在另一个包中添加实体

I wanted to ask about adding an entity in one bundle through a form of an entity in an other different bundle.

I feel this is impossible in symfony because when I tried it, I got a warning.

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 

Any ideas???

  • 写回答

1条回答 默认 最新

  • duanli0453 2013-05-02 10:37
    关注

    Ok create a form type for your entity and set the 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',
        ));
    }
    

    Now in the main form add the newly created form:

    public function buildForm(FormBuilderInterface $builder, array $options)
    {        
        ...
        $builder->add('mySecondEntity', new MySecondEntityFormType());
    }
    
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'compound' => true
        ));
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器