Bonjour,
J'ai ce code qui provient de la documentation officielle:
Le use Symfony\Component\Validator\Validator\ValidatorInterface est bien présent par contre j'obtiens l'erreur suivante:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 <?php namespace App\Controller; use App\Entity\Product; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Validator\Validator\ValidatorInterface; class ProductController extends AbstractController { /** * @Route("/create_product", name="create_product") */ public function createProduct(ValidatorInterface $validator): Response { $product = new Product(); $product->setName(null); $product->setPrice('1999'); $errors = $validator->validate($product); if (count($errors) > 0) { return new Response((string) $errors, 400); } } }
Comment puis je résoudre ce problème?(1/1) InvalidArgumentException
Cannot determine controller argument for "App\Controller\ProductController::createProduct()": the $validator argument is type-hinted with the non-existent class or interface: "Symfony\Component\Validator\Validator\ValidatorInterface".
Merci par avance








Répondre avec citation
Partager