Symfony中的未知实体名称空间别名由Guard身份验证

时间:2017-05-07 16:38:16

标签: symfony login

我正在使用2个独立的实体管理器进行Guard身份验证。

这是我的配置:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   pdo_mysql
                host:     '%database_host%'
                port:     '%database_port%'
                dbname:   '%database_name%'
                user:     '%database_user%'
                password: '%database_password%'
                charset:  UTF8
            backoffice:
                driver:   pdo_mysql
                host:     '%database_backoffice_host%'
                port:     '%database_backoffice_port%'
                dbname:   '%database_backoffice_name%'
                user:     '%database_backoffice_user%'
                password: '%database_backoffice_password%'
                charset:  UTF8

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    default_entity_manager: default
    entity_managers:
        default:
            connection: default
            mappings:
                AppBundle:  ~
                CarBundle: ~
        backoffice:
            connection: backoffice
            mappings:
                BackofficeBundle: ~

这是我的安全设置

services:
    backoffice.form_login_authenticator:
            class: BackofficeBundle\Security\FormLoginAuthenticator
            arguments: ["@router", "@security.password_encoder", "@doctrine.orm.backoffice_entity_manager"]

登录表单后,找到了用户,并且重定向到我的主路径/ backofice,但是我变成了这个错误:

[2017-05-07 18:32:56] request.INFO: Matched route "backoffice_home". {"route":"backoffice_home","route_parameters":{"_controller":"BackofficeBundle\\Controller\\DefaultController::indexAction","_route":"backoffice_home"},"request_uri":"http://ip/backoffice","method":"GET"} []
[2017-05-07 18:32:56] security.DEBUG: Read existing security token from the session. {"key":"_security_main"} []
[2017-05-07 18:32:56] request.CRITICAL: Uncaught PHP Exception Doctrine\ORM\ORMException: "Unknown Entity namespace alias 'BackofficeBundle'." at /home/metahub/autotrader/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php line 271 {"exception":"[object] (Doctrine\\ORM\\ORMException(code: 0): Unknown Entity namespace alias 'BackofficeBundle'. at /home/metahub/autotrader/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php:271)"} []

2 个答案:

答案 0 :(得分:1)

解决方案是:

security:
    encoders:
            BackofficeBundle\Entity\User: bcrypt
    providers:
        database_users:
            entity:
                class: BackofficeBundle:User
                property: username
                manager_name: backoffice

我们需要设置经理" manager_name"对于此实体直接在安全设置中。

答案 1 :(得分:0)

尝试使用auto_mapping: true

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    default_entity_manager: default
    entity_managers:
        default:
            connection: default
            auto_mapping: true
            mappings:
                AppBundle:  ~
                CarBundle: ~
        backoffice:
            connection: backoffice
            auto_mapping: true
            mappings:
                BackofficeBundle: ~