jeudi 12 octobre 2017

$this->container is NULL in Controller on Symfony3

I got an annoying problem when I call this in a controller (ClientDomainController) :

    $this->getDoctrine()->getManager();

I got this error :

    Call to a member function has() on null

I looked the stack trace and see that :

    $this->container is null

My controller extends from the Symfony Controller component :

    use Symfony\Bundle\FrameworkBundle\Controller\Controller;

The funny thing is that in an other controller (HomeController) I make the exact same things :

  1. Extend from Controller (the exact same class)
  2. Get Doctrine
  3. Get the EntityManager
  4. Use the manager

And this without any error.

The only one difference between the HomeController and the ClientDomainController is that the second one is a service. So I wrote it in the services.yml file :

    services:
        client_domain:
            class: AppBundle\Controller\ClientDomainController

Finally I tested many things like creating a constructor to my controller and adding this to the services.yml file (things that a never did to the functional one) :

    arguments: [ 'doctrine.orm.entity_manager' ]

Does somebody can help me please ? :)

Have a nice day ;)




Aucun commentaire:

Enregistrer un commentaire