__construct() must implement interface SymfonyComponentHttpKernelKernelInterface

  sonata-admin, symfony, symfony4

I want to use KernelInterface in an AbstractAdmin class of sonata admin, using symfony 4.

use SymfonyComponentHttpKernelKernelInterface;

class LocationsAdmin extends AbstractAdmin
{
  private $kernel;

public function __construct(string $code, string $class, string $baseControllerName, KernelInterface $appKernel)
{
    parent::__construct($code, $class, $baseControllerName);

    $this->kernel = $appKernel;
}

But i got that

Argument 4 passed to AppAdminXXXAdmin::__construct() must
implement interface SymfonyComponentHttpKernelKernelInterface, null
given, called in
/Users/ugolaf/gcg/rentil/var/cache/de_/Container8jI612X/getAdmin_LocationsService.php
on line 26

So I tried to set autowire in my services.yaml like this :

services:
# default configuration for services in *this* file
_defaults:
    autowire: true      # Automatically injects dependencies in your services.
    autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
    public: false       # Allows optimizing the container by removing unused services; this also means
                        # fetching services directly from the container via $container->get() won't work.
                        # The best practice is to be explicit about your dependencies anyway.

admin.XXX:
    class: AppAdminXXXAdmin
    arguments: [~, AppEntityXXX, AppControllerCRUDController, ~]
    tags:
    - { name: sonata.admin, manager_type: orm, group: "Locations", label: Locations, on_top: true, icon: "<i class="fa fa-key"></i>" }
    autowire: true
    public: true

But I still have the same issue after clearing cache.

Source: Symfony Questions

LEAVE A COMMENT