skip to Main Content

I’m trying to access the EasyCorpBundleEasyAdminBundleDtoPaginatorDtoin my Crud Controller :

public function __construct(
        private EntityManagerInterface $manager,
        private EntityRepository $entityRepository,
        private PaginatorDto $paginatorDto,
    ) {
    }

But I’ve got this error => Cannot autowire service "AppControllerActivityActivityCrudController": argument "$paginatorDto" of method "__construct()" references class "EasyCorpBundleEasyAdminBundleDtoPaginatorDto" but no such service exists. and I don’t understand why and How to fix it 🙁

Any idea ?

2

Answers


  1. I’m not an expert of that bundle so take my answer with a pinch of salt but looking at bundle’s code I’ve noticed PaginatorDto not to be a service (as the name suggests).

    As that DTO is not a service (and it’s ok it is not), you can’t autowire it nor make it a service "locally" (eg.: in your application).

    So, in order to retrieve the DTO object, inject AdminContextProvider (that is a service as you can notice here) instead and use it to get the DTO

    $adminContext->getCrud()->getPaginator();
    
    Login or Signup to reply.
  2. Your crud controller should extend AbstractCrudController which give you access to the current admin context.

    So if you want to use it in one of your crud controller method you should be able to access the paginator with:

    $paginator = $this->getContext()->getCrud()->getPaginator();
    

    If you want to do the same outside your crud controller, let’s say in another service. You need to inject the AdminContextProvider to first get the AdminContext and do it the same way.

    private ?AdminContext $siteRepository;
    
    public function __construct(AdminContextProvider $adminContextProvider)
    {
        $this->adminContext = $adminContextProvider->getContext();
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search