Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument passed to controller must be an instance of ContainerInterface, instance of appDevDebugProjectContainer given

Why do I have this error?

Catchable Fatal Error: Argument 1 passed to Application\Sonata\ProductBundle\Controller\ProductAdminController::__construct() must be an instance of ContainerInterface, instance of appDevDebugProjectContainer given

Here is my services.yml:

services:
    product_admin_controller:
      class: Application\Sonata\ProductBundle\Controller\ProductAdminController
      arguments: ["@service_container"]
      tags:
            - { name: doctrine.event_listener, event: postLoad, connection: default  }

And my controller:

class ProductAdminController extends Controller
{
    protected $container;

    public function __construct(\ContainerInterface $container)
    {
        $this->container = $container;
    }
}
like image 869
Ophiuchus Avatar asked Sep 30 '22 00:09

Ophiuchus


1 Answers

You have to inject the container by the "calls" option, not as an argument i think :

services:
    product_admin_controller:
      class: Application\Sonata\ProductBundle\Controller\ProductAdminController
      arguments: ["@another_service_you_need"]
      tags:
            - { name: doctrine.event_listener, event: postLoad, connection: default  }
      calls:
            -   [ setContainer,["@service_container"] ]

Also, don't forget to create the public method "setContainer()" in your listener class.

like image 168
Keiro Avatar answered Oct 06 '22 03:10

Keiro