We have service as
services:
service_name:
class: One\SomeBundle\Controller\OurController
What need we add, to make $this->getDoctrine() works in our “OurController” ?
I tried in “OurController”
$this->countainer->get('doctrine')
// and
$this->getDoctrine()
but nothing happens, just errors.
I want that this controller use native methods such as $this->getDoctrine(). As I know we can give arguments to controller(arguments in services.yml), and then apply it, but can we set it as default? Without
function __construct($em)
{
$this->em = $em;
}
and other additional stuff. All i need is to make $this->getDocrine() works.
i think the doctrine is avaiable in all controllers like this
$em = $this->getDoctrine()->getEntityManager();if you want the doctrine available in your service then use something like this