Symfony2使用带有fosuserbundle的多个数据库

时间:2015-08-18 22:16:11

标签: php symfony doctrine-orm fosuserbundle

我正在尝试在一个symfony2项目中使用2个不同的实体管理器实现fosuserbundle。我正在使用https://github.com/rollerworks/RollerworksMultiUserBundle来完成这一切。 我已经按照文档中的所有步骤操作,但是我遇到了错误,我不知道为什么......

MappingException in MappingException.php line 37:
The class 'IntoPeople\AdminBundle\Entity\User' was not found in the chain
configured namespaces FOS\UserBundle\Model

所以这个映射应该在我的security.yml中配置。我从multiuserbundle文档中复制了以下内容:

orm:
    default_entity_manager: default
    entity_managers:
        default:
            connection: default
            mappings:
                FOSUserBundle:
                    type:        xml
                    dir:         '%kernel.root_dir%/../vendor/friendsofsymfony/user-bundle/Resources/config/doctrine-mapping'
                    prefix:      FOS\UserBundle\Model
                    is_bundle:   false


        customer:
            connection: customer
            mappings:
              FOSUserBundle:
                  type:        xml
                  dir:         '%kernel.root_dir%/../vendor/friendsofsymfony/user-bundle/Resources/config/doctrine-mapping'
                  prefix:      FOS\UserBundle\Model
                  is_bundle:   false

所以基本上atm我不确定我应该改变什么。我试着设置:

mappings:
    FosUserBundle: ~

但这不起作用。

有人知道如何解决这个问题吗?

提前致谢。

编辑:

好的,所以我改变了我的配置

orm:
    default_entity_manager: default
    entity_managers:
        default:
            connection: default
            mappings:
                IntoPeopleAdminBundle: ~


        customer:
            connection: customer
            mappings:
                IntoPeopleDatabaseBundle: ~

但我仍然收到错误,现在看起来像这样:

The class 'IntoPeople\DatabaseBundle\Entity\User' was not found in the chain 
configured namespaces IntoPeople\AdminBundle\Entity, FOS\UserBundle\Model

1 个答案:

答案 0 :(得分:0)

更改

orm:
  default_entity_manager: default
  entity_managers:
    default:
      connection: default
        mappings:
          FOSUserBundle:
            type: xml
            dir: '%kernel.root_dir%/../vendor/friendsofsymfony/user-bundle/Resources/config/doctrine-mapping'
            prefix:  FOS\UserBundle\Model
            is_bundle:  false


      customer:
        connection: customer
        mappings:
          FOSUserBundle:
            type: xml
            dir: '%kernel.root_dir%/../vendor/friendsofsymfony/user-bundle/Resources/config/doctrine-mapping'
            prefix: FOS\UserBundle\Model
            is_bundle: false

orm:
  default_entity_manager: default
  entity_managers:
    default:
      connection: default
        mappings:
          IntoPeopleAdminBundle: ~


      customer:
        connection: customer
        mappings:
          IntoPeopleAdminBundle: ~

在扩展基类时,不需要为FOSUserBundle定义映射。该解决方案应该有效。