l'interface "Doctrine\Common\Persistence\ObjectManager" mais aucun service de ce type n'existe
Bonsoir,
Je reçois ce message d'erreur alors que j'ai bien tout déclarer je pense, avez vous une idée ?
Code:
1 2
|
Cannot autowire service "App\Controller\Admin\AdminPropertyController": 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 : AdminPropertyController.php
Code:
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 62 63
|
<?php
namespace App\Controller\Admin;
use App\Entity\Property;
use App\Form\PropertyType;
use App\Repository\PropertyRepository;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class AdminPropertyController extends AbstractController
{
/**
* @var PropertyRepository
*/
private $repository;
/**
* @var ObjectManager
*/
private $em;
public function __construct(PropertyRepository $repository, ObjectManager $em)
{
$this->repository = $repository;
$this->em = $em;
}
/**
* @Route("/admin", name="admin.property.index")
* @return \Symfony\Component\HttpFoundation\Response
*/
public function index()
{
$properties = $this->repository->findAll();
return $this->render('admin/property/index.html.twig', compact('properties'));
}
/**
* @Route("/admin/{id}", name="admin.property.edit")
* @param Property $property
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function edit(Property $property, Request $request)
{
$form = $this->createForm(PropertyType::class, $property);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->flush();
return $this->redirectToRoute('admin.property.index');
}
return $this->render('admin/property/edit.html.twig', [
'property' => $property,
'form' => $form->createView()
]);
}
} |