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 FOS\UserBundle\Doctrine\UserManager::__construct() must be an instance of Doctrine\Common\Persistence\ObjectManager, instance of Doctrine\ORM\EntityManager given, called in /url/to/symfony/proyect/var/cache/dev/ContainerKx7xY28/srcApp_KernelDevDebugContainer.php on line 1466
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:
FOS\UserBundle\Model\UserInterface: 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: App\Entity\User
from_email:
address: "[email protected]"
sender_name: "[email protected]"
src/Entity/User.php
<?php
// src/Entity/User.php
namespace App\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
EDIT: I just tried the same guide with symfony 4.3 and it's work! so i think is something about compability of symfony 4.4 and FOSUserBundle...
This is not a problem related to the fos user bundle, but with your declaration of user.
Read this post first.
See your User declaration :
Try replace it with
You may have somewhere in your code where you use an entity object which is declared with ObjectManager instead of EntityManagerInterface.
Please if this is not working explain why you add this line :
EDIT
Ok I've been looking for it, and that's look like a bug with doctrine. I found this issue : https://github.com/doctrine/orm/issues/8242.
It solve your problem.
Just update your composer.json like :