Symfony2 404 error: Object Not Found (ParamConverter error)
13,877
Your route should contain post
param.
@Route("/search/{post}", name="shrubs_search")
Also your method should take this param as method argument.
Author by
bigmammoo
Updated on June 05, 2022Comments
-
bigmammoo almost 2 years
I created a new boundary class called search.html.twig, but when I go to the URL (http://localhost:8000/shrubs/search) I get the following error:
ERROR - Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "AppBundle\Entity\Shrubs object not found." at C:\Users\rosmith\shrub_search\vendor\sensio\framework-extra-bundle\Request\ParamConverter\DoctrineParamConverter.php line 66
There must be something wrong with my ParamConverter? Are my annotations correct? I read the symfony documentation but it just doesn't make sense to me. Here's my controller:
/** * Finds and displays a shrub entity. * * @Route("/search", name="shrubs_search") * @ParamConverter("post", class="AppBundle:Shrubs") */ private function searchAction(Request $request) { $shrub = new Shrubs(); $form = $this->createForm('AppBundle\Form\ShrubsType', $shrub) ->add('botanicalname', TextType::class, array('label' => 'Botanical Name:')) ->add('commonname', TextType::class, array('label' => 'Common Name:')) ->add('wetsoil', CheckboxType::class, array('label' => 'Tolerates Wet Soil:')) ->add('moistsoil', CheckboxType::class, array('label' => 'Prefers Moist Soil:')) ->add('peatysoil', CheckboxType::class, array('label' => 'Prefers Peaty Soil:')) ->add('welldrainedsoil', CheckboxType::class, array('label' => 'Prefers Well-drained Soil:')) ->add('drought', CheckboxType::class, array('label' => 'Tolerates Drought:')) ->add('claysoil', CheckboxType::class, array('label' => 'Tolerates Clay Soil:')) ->add('sandysoil', CheckboxType::class, array('label' => 'Prefers Sandy Soil:')) ->add('loamsoil', CheckboxType::class, array('label' => 'Prefers Loam Soil:')) ->add('infertilesoil', CheckboxType::class, array('label' => 'Tolerates Infertile Soil:')) ->add('richsoil', CheckboxType::class, array('label' => 'Prefers Rich Soil:')) ->add('compactedsoil', CheckboxType::class, array('label' => 'Tolerates Compacted Soil:')) ->add('cityconditions', CheckboxType::class, array('label' => 'Tolerates City Conditions:')) ->add('pollution', CheckboxType::class, array('label' => 'Tollerates Pollution:')) ->add('salt', CheckboxType::class, array('label' => 'Tolerates Salt Conditions:')) ->add('windy', CheckboxType::class, array('label' => 'Tolerates Windy Conditions:')) ->add('shade', CheckboxType::class, array('label' => 'Prefers Shade:')) ->add('partshade', CheckboxType::class, array('label' => 'Prefers Part Shade:')) ->add('fullsun', CheckboxType::class, array('label' => 'Prefers Full Sun:')) ->add('pestproblem', CheckboxType::class, array('label' => 'Pest Problem:')) ->add('borderlinehardy', CheckboxType::class, array('label' => 'BorderLine Hardy')); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($shrub); $em->flush($shrub); return $this->redirectToRoute('shrubs_show', array('id' => $shrub->getNumber())); } return $this->render('shrubs/new.html.twig', array( 'shrub' => $shrub, 'form' => $form->createView(), )); }
-
bigmammoo about 7 yearsi changed the annotation to:
-
bigmammoo about 7 years/** * Finds and displays a shrub entity. * * @Route("/search/{post}", name="shrubs_search") * @ParamConverter("post", class="AppBundle:Shrubs") */
-
Matteo about 7 yearsthe URL posted in the question don't specify any id so probably is only a typo and don't really need a paramconverter here
-
bigmammoo about 7 yearsIt's the same error, even if I remove the paramcoverter part
-
bigmammoo about 7 yearsI just have this annotation: @Route("/search", name="shrubs_search")
-
michail_w about 7 yearsIf you still face the same error even if I remove the paramcoverter part, it looks like cache problem.
-
bigmammoo about 7 yearsI try with and without post
-
bigmammoo about 7 yearsI did clear the cache. Really scratching my head here
-
bigmammoo about 7 yearsOh, I figured it out. I had to change the controller method from private to public. Thank you both so much for your help
-
Vladimir Ch over 6 yearsI have a same problem: 2 almost equals, public function, 2 vars in, object and string. One can find Entity obj, other can't find the tame entity lol