Bonsoir,
J'ai un soucis je reçois ce message d'erreur, je pense que tout est bon dans mon code ?
Avez vous une idée ?
Mon source : PropertyController.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part Cannot autowire service "App\Controller\PropertyController": argument "$em" of method "__construct()" references interface "Doctrine\Common\Persistence\ObjectManager" but no such service exists. Did you create a class that implements this interface?
Mon source : PropertyRepository.php
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 <?php namespace App\Controller; use App\Entity\Property; use App\Repository\PropertyRepository; use Doctrine\Common\Persistence\ObjectManager; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; class PropertyController extends AbstractController { /** * @var PropertyRepository */ private $repository; /** * @var ObjectManager */ private $em; public function __construct(PropertyRepository $repository, ObjectManager $em) { $this->repository = $repository; $this->em = $em; } /** * @Route("/biens", name="property.index") * @return Response */ public function index(): Response { $property = $this->repository->findAllVisible(); $property[0]->setSold(true); $this->em->flush(); return $this->render('property/index.html.twig', [ 'current_menu' => 'properties' ]); } }
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 <?php namespace App\Repository; use App\Entity\Property; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; /** * @method Property|null find($id, $lockMode = null, $lockVersion = null) * @method Property|null findOneBy(array $criteria, array $orderBy = null) * @method Property[] findAll() * @method Property[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ class PropertyRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, Property::class); } /** * @return Property[] */ public function findAllVisible(): array { return $this->createQueryBuilder('p') ->where('p.sold = false') ->getQuery() ->getResult(); } // /** // * @return Property[] Returns an array of Property objects // */ /* public function findByExampleField($value) { return $this->createQueryBuilder('p') ->andWhere('p.exampleField = :val') ->setParameter('val', $value) ->orderBy('p.id', 'ASC') ->setMaxResults(10) ->getQuery() ->getResult() ; } */ /* public function findOneBySomeField($value): ?Property { return $this->createQueryBuilder('p') ->andWhere('p.exampleField = :val') ->setParameter('val', $value) ->getQuery() ->getOneOrNullResult() ; } */ }
Partager