V
V
Voroncheg2018-11-20 02:08:01
symfony
Voroncheg, 2018-11-20 02:08:01

Symfony 4. Fos user bundle. How to reach 'fos_user.user_manager'?

Hello. I'm learning symfony 4. (I haven't studied earlier versions). In general, I started writing task tracker lessons there. You can create, edit, delete tasks, admin added. (Used FOSUserBundle). Then it's time to write the conclusions of the tasks for individual users. Added dropdown of users to the creation of a task using the doctrine. All right. Idishka is recorded. But I noticed that there is a user that I demoted earlier. Understood that it is more correct to use api FOS. Got on thisdoc. And that's all. Writes that there is no such service in get('fos_user.user_manager'). I've been sitting for a week now. Please someone guide me on the right path. What to do? Configure security.yaml and fos_user.yaml so that this service goes to my controller? Make a new class and implement FOS\UserBundle\Doctrine\UserManager there? Or all together? (The first time I encountered interfaces and abstract classes). Tell me please. I want to get something like $this->container->get('fos_user.user_manager')->findUsers().

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Martin Alekseevich, 2018-11-20
@martin_alekseevich

Services in the four are private by default and cannot be accessed through the container. Injecting FOS\UserBundle\Model\UserManagerInterface into the constructor or method of the desired class will solve the problem

private $manager;

    public function __construct(UserManagerInterface $manager)
    {
        $this->manager = $manager;
    }

     public function fooMethod(User $user): void
     {
         $this->manager->updateUser($user);
     }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question