0

I'm developing a new project with Symfony that will have a website and an admin site in the same bundle. I have 2 different connections (one for the data database and one for the admin database) and I wanted to be able to distinguish between entities so for that I have this config.yml:

doctrine:
  dbal:
      default_connection: project
      connections:
          project:
              driver:   pdo_pgsql
              host:     '%database_host%'
              port:     '%database_port%'
              dbname:   '%database_name%'
              user:     '%database_user%'
              password: '%database_password%'
              charset:  UTF8
          backoffice:
              driver:   pdo_pgsql
              host:     '%backoffice_database_host%'
              port:     '%backoffice_database_port%'
              dbname:   '%backoffice_database_name%'
              user:     '%backoffice_database_user%'
              password: '%backoffice_database_password%'
              charset:  UTF8

  orm:
      default_entity_manager: project
      entity_managers:
          project:
              naming_strategy: doctrine.orm.naming_strategy.underscore
              connection: project
              auto_mapping: true
              mappings:
                    # you must specify the type
                    type:     "annotation"    
                    # The directory for entity (relative to bundle path)
                    dir:      "Entity/project"
                    #the prefix 
                    prefix:   "Project\\ProjectBundle\\Entity\\Project"
          backoffice:
              naming_strategy: doctrine.orm.naming_strategy.underscore
              connection: backoffice
              mappings:
                    # you must specify the type
                    type:     "annotation"    
                    # The directory for entity (relative to bundle path)
                    dir:      "Entity/Backoffice/"
                    #the prefix 
                    prefix:   "Project\\ProjectBundle\\Entity\\Backoffice"

Now I'm trying to configure FOSUserBundle and when I want to update the schema for the backoffice database I get the following error: The class 'Project\ProjectBundle\Entity\Backoffice\User' was not found in the chain configured namespaces Project\ProjectBundle\Entity\Project, FOS\U serBundle\Model. The FOSUserBundle configuration is:

fos_user:
    db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
    firewall_name: backoffice
    user_class: Project\ProjectBundle\Entity\Backoffice\User
    from_email:
        address: "%mailer_user%"
        sender_name: "%mailer_user%"

Is there any way to achieve that? Another solution that I thought of is having a Bundle with only the project database entities, but I don't know if that would be too complex.

Thanks

Khriz
  • 5,888
  • 6
  • 34
  • 39
  • 1
    Try setting model_manager_name to backoffice under the fos_user config. This answer is a bit verbose but seems to address the same issue: http://stackoverflow.com/questions/14475180/multiple-entity-manager-for-fosuserbundle – Cerad Mar 22 '17 at 14:23
  • Wow! That totally does it. Thanks a lot. Please post it a an answer and I'll accept it. – Khriz Mar 22 '17 at 14:49
  • 1
    Just vote for the linked answer and we will call it even. – Cerad Mar 22 '17 at 15:13
  • That does not make justice to the help you provided, but ok ;). Thanks again! – Khriz Mar 22 '17 at 15:20

0 Answers0