I need to retrieve my repository in my function in a Custom Controller I've created but it gives me the following error:
{"code":500,"message":"Could not resolve argument $em of \"App\\Controller\\LicenceController::getlicencecodecrm()\", maybe you forgot to register the controller as a service or missed tagging it with the \"controller.service_arguments\"?"}
sylius_ressource.yaml:
sylius_resource:
resources:
############## Licence ##############
app.licence:
driver: doctrine/orm # You can use also different driver here
classes:
model: App\Entity\Licence\Licence
repository: App\Repository\LicenceRepository
form : App\Form\LicenceType
services.yaml :
App\Controller\LicenceController:
autowire: false
public: true
LicenceController.php :
` public function getLicenceCodeCrm(Request $request, EntityManagerInterface $em)
{
// $repo = $this->get('App\Repository\LicenceRepository');
$repo = $em->getRepository(Licence::class);
$criteria = $request->query->get('phrase');
$q = $criteria['search']['value'];
$items = $repo->findByNamePart($q);
return new JsonResponse([
'_embedded' => [
'items' => $items,
]
]);
}`
LicenceRepository :
public function findByNamePart(string $codeCrm, ?int $limit = null): array
{
return $this->createQueryBuilder('o')
->andWhere('o.codeCrm LIKE :code')
->setParameter('code', '%' . $codeCrm . '%')
->setMaxResults($limit)
->getQuery()
->getResult();
}