【问题标题】:Symfony2 using multiple databases with fosuserbundleSymfony2 使用带有 fosuserbundle 的多个数据库
【发布时间】:2015-08-18 22:16:11
【问题描述】:

我正在尝试在一个 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

【问题讨论】:

    标签: php symfony doctrine-orm fosuserbundle


    【解决方案1】:

    改变

    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 定义映射,因为您正在扩展它的基类。该解决方案应该有效。

    【讨论】:

    • 错误只是现在稍微改变了一点:在链配置的命名空间 IntoPeople\AdminBundle\Entity、FOS\UserBundle\Model 中找不到类 'IntoPeople\DatabaseBundle\Entity\User'
    猜你喜欢
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-30
    • 2012-04-07
    • 1970-01-01
    • 2013-04-23
    相关资源
    最近更新 更多