Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony,请求找不到服务_Php_Symfony - Fatal编程技术网

Php Symfony,请求找不到服务

Php Symfony,请求找不到服务,php,symfony,Php,Symfony,当我尝试运行代码时,会收到以下错误消息: 无法自动连接请求的参数$request “App\Controller\AppController::formulaire()”:它引用类 “symfony\Component\HttpFoundation\Request”,但不存在此类服务 我不明白,因为我遵循了教程并查看了symfony文档,它看起来很好 我的代码是: /** * @Route("/form", name="form") *

当我尝试运行代码时,会收到以下错误消息:

无法自动连接请求的参数$request “App\Controller\AppController::formulaire()”:它引用类 “symfony\Component\HttpFoundation\Request”,但不存在此类服务

我不明白,因为我遵循了教程并查看了symfony文档,它看起来很好

我的代码是:

/**
     * @Route("/form", name="form")
     */
    public function formulaire(Request $request)
    {
        $application = new Applications();
        $candidat = new Candidats();
        $annexe = new Annexes();

        $formAnnexe = $this->createFormBuilder($annexe)
                            ->add("fichier")
                            ->getForm();

        $formCandidat = $this->createFormBuilder($candidat)
                            ->add("nom")
                            ->add("prenom")
                            ->add("email")
                            ->getForm();

        $form = $this->createFormBuilder($application)
                    ->add("poste", ChoiceType::class, [
                        'choices'  => [
                        'Choisissez un poste ...' => null,
                        'Chef de Projet' => 'Chef de Projet',
                        'Secrétaire' => 'Secrétaire',
                        'Assistant' => 'Assistant',
                        ],
                    ])
                    ->add('pdf', FileType::class, [
                        'label' => 'Fiche de candidature (PDF)',
        
                        // unmapped means that this field is not associated to any entity property
                        'mapped' => false,
        
                        // make it optional so you don't have to re-upload the PDF file
                        // every time you edit the Product details
                        'required' => false,

                        'constraints' => [
                            new File([
                                'maxSize' => '1024k',
                                'mimeTypes' => [
                                    'application/pdf',
                                    'application/x-pdf',
                                ],
                                'mimeTypesMessage' => 'Please upload a valid PDF document',
                            ])
                        ]
                    ])
                    ->getForm();

        $form->handleRequest($request);
        return $this->render('app/form.html.twig', [
            
            'form' => $form->createView(),
            'formCandidat' => $formCandidat->createView(),
            'formAnnexe' => $formAnnexe->createView(),
        
            
        ]);
    }
   
}
我使用以下方法:

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Applications;
use App\Entity\Candidats;
use App\Entity\Annexes;
use symfony\Component\HttpFoundation\Request;
use Doctrine\Common\Cersistence\ObjectManager;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
在我添加(Request$Request)之前,一切都很好


有人知道哪里出了问题吗?

导入
请求
类时会出现输入错误。 从该名称空间
导入时使用symfony\Component\HttpFoundation\Request小写
s
。 任何导入名称空间都区分大小写。 使用此命名空间<代码>使用Symfony\Component\HttpFoundation\Request