When I try to run my code I get the following error message :
Cannot autowire argument $request of “AppControllerAppController::formulaire()”: it references class “symfonyComponentHttpFoundationRequest” but no such service exists.
I don’t understand as I followed tutorial and checked on symfony documentation and it looks fine!
my code is :
/** * @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(), ]); } }
And I use the followings :
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;
Everthing was fine until I added (Request $request)
Does anyone knows what is wrong ?
Advertisement
Answer
there is a typo when you import the Request
class.
you import from this namespace use symfonyComponentHttpFoundationRequest;
with lower-case s
.
any import namespaces are case-sensitive.
use this namespace. use SymfonyComponentHttpFoundationRequest;