简体   繁体   English

Symfony2 404错误:找不到对象(ParamConverter错误)

[英]Symfony2 404 error: Object Not Found (ParamConverter error)

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: 我创建了一个名为search.html.twig的新边界类,但是当我转到URL( http:// localhost:8000 / shrubs / search )时,我收到以下错误:

ERROR - Uncaught PHP Exception Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException: "AppBundle\\Entity\\Shrubs object not found." 错误 - 未捕获的PHP异常Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException:“找不到AppBundle \\ Entity \\ Shrubs对象。” at C:\\Users\\rosmith\\shrub_search\\vendor\\sensio\\framework-extra-bundle\\Request\\ParamConverter\\DoctrineParamConverter.php line 66 在C:\\ Users \\ rosmith \\ shrub_search \\ vendor \\ sensio \\ framework-extra-bundle \\ Request \\ ParamConverter \\ DoctrineParamConverter.php第66行

There must be something wrong with my ParamConverter? 我的ParamConverter一定有问题吗? Are my annotations correct? 我的注释是否正确? I read the symfony documentation but it just doesn't make sense to me. 我阅读了symfony文档但它对我没有意义。 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(),
        ));
    }

Your route should contain post param. 您的路线应包含post参数。

@Route("/search/{post}", name="shrubs_search")

Also your method should take this param as method argument. 您的方法也应该将此参数作为方法参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM