Symfony 4.4 Error on FOSUserBundle Installation

Hi everyone this is my fist post so sorry in advance!

I followed this two post about "how to install fosuserbundle in symfony 4.4":

https://vfac.fr/blog/how-install-fosuserbundle-with-symfony-4

https://ourcodeworld.com/articles/read/794/how-to-install-and-configure-fosuserbundle-in-symfony-4

But at the end i got this error:

Argument 3 passed to FOSUserBundleDoctrineUserManager::__construct() must be an instance of DoctrineCommonPersistenceObjectManager, instance of DoctrineORMEntityManager
given, called in /url/to/symfony/proyect/var/cache/dev/ContainerKx7xY28/srcApp_KernelDevDebugContainer.php on line 1466

Error image

i didn’t change anything about FOSUserBundle but it’s seems that something is wrong in my configuration…

My config files are these:

security.yaml

security:
    encoders:
        FOSUserBundleModelUserInterface: bcrypt

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

    # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
    providers:
        #users_in_memory: { memory: null }
        fos_userbundle:
            id: fos_user.user_provider.username

    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            #anonymous: lazy
            #provider: users_in_memory
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_token_generator: security.csrf.token_manager

            logout:       true
            anonymous:    true

    # Easy way to control access for large sections of your site
    # Note: Only the *first* access control that matches will be used
    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN }

packages/fos_user.yaml

# config/packages/fos_user.yaml
fos_user:
    db_driver: orm # other valid values are 'mongodb' and 'couchdb'
    firewall_name: main
    user_class: AppEntityUser
    from_email:
        address: "[email protected]"
        sender_name: "[email protected]"

src/Entity/User.php

<?php
// src/Entity/User.php

namespace AppEntity;

// AƱadimos esta linea porque parece que hacer algo...
use DoctrineCommonPersistenceObjectManager;

use FOSUserBundleModelUser as BaseUser;
use DoctrineORMMapping as ORM;

/**
 * @ORMEntity
 * @ORMTable(name="fos_user")
 */
class User extends BaseUser
{
    /**
     * @ORMId
     * @ORMColumn(type="integer")
     * @ORMGeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct()
    {
        parent::__construct();
        // your own logic
    }
}

i’m looking for your answer, Thanks!

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *