Bonsoir tout le monde,

j'ai vraiment besoin de votre aide s'il vous plait, je viens juste de finir mon projet ensuite, donc je voulais a faire un test générale. Du coup quand je voulais enrégistrer une agence et j'ai eu cette erreure (App\Entity\Property object not found by the @ParamConverter annotation)
Aidez moi à résoudre se problem

Ici c'est mon PropertyController

"  class PropertyController extends AbstractController
{
    #[Route('profile/property', name: 'app_property_index', methods: ['GET'])]
    public function index(PropertyRepository $propertyRepository): Response
    {
        return $this->render('property/index.html.twig', [
            'properties' => $propertyRepository->findBy(['auteur'=>$this->getUser()])

        ]);

    }

    #[Route('/profile/new', name: 'app_property_new', methods: ['GET', 'POST'])]
    public function new(Request $request, PropertyRepository $propertyRepository): Response
    {
        $property = new Property();
        $form = $this->createForm(PropertyType::class, $property);
        $form->handleRequest($request);
        $property->setAuteur($this->getUser());

        if ($form->isSubmitted() && $form->isValid()) {
            $propertyRepository->add($property, true);
             $this->addFlash('success', 'Offre ajouter avec succès');

            return $this->redirectToRoute('app_property_index', [], Response::HTTP_SEE_OTHER);
        }

        return $this->renderForm('property/new.html.twig', [
            'property' => $property,
            'form' => $form,
        ]);
    } "
/**
     * @Route("/{slug}-{id}", name="app_property_show", requirements={"slug": "[a-z0-9\-]*"})
     *  @return Response
     */

    public function show(Property $property, string $slug, Request $request, ContactNotification $notification ): Response
    {
        if ($property->getSlug() !== $slug ) {
            return $this->redirectToRoute('app_offre', [
                'id'  => $property->getId(),
                'slug' => $property->getSlug()
            ], 301);
        }

        if ($property->getAuteur()==$this->getUser()){
                     return $this->render('property/show.html.twig', [
                'property' => $property,
                ]);
        }

        $contact = new Contact();
        $contact->setProperty($property);
        $form = $this->createForm(ContactType::class, $contact);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()){
            $notification->notify($contact);
            $this->addFlash('success', 'Votre email a bien été envoyé' );
             return $this->render('property/show1.html.twig', [
                'id'  => $property->getId(),
                'slug' => $property->getSlug(),
                'property' => $property,
                'form' => $form->createView()
            ]);

        }

           return $this->render('property/show1.html.twig', [
            'property' => $property,
            'form' => $form->createView()
        ]);

    }

Toujours mon PropertyController

/**
     * @Route("/{id}/edit", name="app_property_edit", methods= {"GET", "POST"})
     */
    public function edit(Request $request, Property $property, PropertyRepository $propertyRepository): Response
    {
        if ($property->getAuteur()==$this->getUser()){

                $form = $this->createForm(PropertyType::class, $property);
                $form->handleRequest($request);

                if ($form->isSubmitted() && $form->isValid()) {
                    $property->setupdatedAt(new \dateTime);
                    $propertyRepository->add($property, true);
                    $this->addFlash('success', 'Offre modifier avec succès');

                    return $this->redirectToRoute('app_property_index', [], Response::HTTP_SEE_OTHER);
                }

                    return $this->renderForm('property/edit.html.twig', [
                        'property' => $property,
                        'form' => $form,
                    ]);
                return $this->redirectToRoute('app_property_index', [], Response::HTTP_SEE_OTHER);

        }

    }

    #[Route('/{id}', name: 'app_property_delete', methods: ['POST'])]
    public function delete(Request $request, Property $property, PropertyRepository $propertyRepository): Response
    {
        if ($property->getAuteur()==$this->getUser()){

            if ($this->isCsrfTokenValid('delete'.$property->getId(), $request->request->get('_token'))) {
                $propertyRepository->remove($property, true);
                $this->addFlash('success', 'Offre supprimer avec succès');

            }
                    return $this->redirectToRoute('app_property_index', [], Response::HTTP_SEE_OTHER);

        }

        return $this->redirectToRoute('app_property_index', [], Response::HTTP_SEE_OTHER);
    }

}

S'il vous plait aidez-moi à résoudre ce problème

2 réponses


Orivoir21
Réponse acceptée

Bonjour, est-ce que la ligne:

use App\Entity\Property;

n'a pas était oubliée en haut du fichier ?

C'est sur quelle route que tu obtiens cette erreur ?

Peut-être que pour cette route:

/**
* @Route("/{slug}-{id}", name="app_property_show", requirements={"slug": "[a-z0-9\-]*"})
* @return Response
*/
public function show(Property $property, string $slug, Request $request, ContactNotification $notification ): Response;

Il te faut définir un custom fetch pour que le ParamConverter sache comment aller chercher l'entité car tu as 2 wildcard dans ta requête.

/**
* @Route("/{slug}-{id}", name="app_property_show", requirements={"slug": "[a-z0-9\-]*"})
* @Entity("property", expr="repository.findOneBy(id)") 
* @return Response
*/
public function show(Property $property, string $slug, Request $request, ContactNotification $notification ): Response;

Tu peux aussi jeter un oeil a la documentation du ParamConverter pour en s'avoir plus.

Gamzo20
Auteur

j'ai belle et bien utiliser " use App\Entity\Property " et de plus j'ai essaiyé d'ajouté la ligne que tu as complèter, mais pourtant sa me montre la meme erreur. De plus pour plus de précision c'est le tuto de grafikart que j'ai régarder pour pouvoir faire sa. Par conséquent je suis un débutant.