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