Symfony,Request找不到服务



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

无法自动连接的参数$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 SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;
use AppEntityApplications;
use AppEntityCandidats;
use AppEntityAnnexes;
use symfonyComponentHttpFoundationRequest;
use DoctrineCommonCersistenceObjectManager;
use SymfonyComponentFormExtensionCoreTypeChoiceType;
use SymfonyComponentFormExtensionCoreTypeFileType;
use SymfonyComponentValidatorConstraintsFile;
use SymfonyComponentFormAbstractType;
use SymfonyComponentOptionsResolverOptionsResolver;

在我添加(请求$Request(之前,一切都很好

有人知道出了什么问题吗?

导入Request类时出现拼写错误。从该名称空间CCD_ 2导入时使用小写CCD_。任何导入命名空间都区分大小写。使用此命名空间。use SymfonyComponentHttpFoundationRequest;

最新更新