F
F
ff0xff2019-02-04 13:27:18
symfony
ff0xff, 2019-02-04 13:27:18

How to get doctrine container service in symfony 4?

Good day to all, tell me how you can access the doctrine container in an empty class?
I have a class:

class MyClass{
  public function work(){
      $doctrine = $this->getContainer()->get('doctrine'); // я хочу сделать что то вроде этого
  }
}

Usually I wrote in the controller $this->getContainer()->get('doctrine'); and everything worked, but how to do it in a simple class?
What should be written in use? Should a class inherit something?
Tell me who knows?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Artemy Lapko, 2019-02-04
@artemylapko

You don't need a doctrine container in an empty class.
What do you want to do in this case? This is done in other ways.

A
Alexander Novikov, 2019-02-04
@AlexndrNovikov

Documentation section explaining how this is done:
https://symfony.com/doc/current/service_container....

D
Denis, 2019-02-04
@prototype_denis

Maybe help here https://github.com/krakjoe/pthreads/issues/369

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question