I’m trying to access the EasyCorpBundleEasyAdminBundleDtoPaginatorDto
in 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
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 DTOYour 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:
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 theAdminContext
and do it the same way.