F
F
ff0xff2018-10-30 02:46:55
symfony
ff0xff, 2018-10-30 02:46:55

Get doctrine container in symfony 4?

tell me how to get an instance of the doctrine class
In all examples they write something like:
$this->getDoctrine()
$this->getContener->get('doctrine');
how to get it without $this ?
What namespace is needed? my class does not inherit a bunch of everything.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
index0h, 2018-10-30
@index0h

Use dependency injection

G
GTRxShock, 2018-10-30
@GTRxShock

use Symfony\Bridge\Doctrine\RegistryInterface;
// ...
protected $doctrine;
// ...
public function __construct(RegistryInterface $registry)
{
    // доктрина ($registry) в констуктор заинжектится сама
    $thits->doctrine = $registry;
}

A
Artemy Lapko, 2018-10-30
@artemylapko

Can you give an example why you need it? Maybe you don't need a copy of the doctrine?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question