简体   繁体   中英

Symfony2 using multiple databases with fosuserbundle

I'm trying to implement fosuserbundle with 2 diffrent entity managers in one symfony2 project. I'm using https://github.com/rollerworks/RollerworksMultiUserBundle to get this all done. I've followed all the steps in the documentation but I've gotten an error and I don't know why ..

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

So this mapping should be configured in my security.yml. I copied the following from the multiuserbundle documentation:

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

So basically atm I'm not sure what I should change. I've tried to just set:

mappings:
    FosUserBundle: ~

But this doesn't work.

Anybody know how I can fix this?

Thanks in advance.

EDIT:

Ok so I changed my config

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


        customer:
            connection: customer
            mappings:
                IntoPeopleDatabaseBundle: ~

But I'm still getting error, now it looks like this:

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

Change

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

to

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


      customer:
        connection: customer
        mappings:
          IntoPeopleAdminBundle: ~

You don't need to define mappings for FOSUserBundle as you're extending its base class. That solution should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM