Answer the question
In order to leave comments, you need to log in
Is it possible and necessary and is it necessary to take the Symfony form to the service, or is it better to leave it in the controller?
1. Is it possible to take the form to the service?
2. Do I need to take out the form?
3. Is it possible to transfer this code (except for view rendering) to a service (do they write like this)?
public function present(Proposition $proposition, Request $request, CVService $CVService): Response
{
$candidate = new Candidate();
$form = $this->createForm(CandidateType::class, $candidate);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
if($CVService->present($proposition, $candidate)) {
$this->addFlash(
'success',
'CV was sent'
);
} else {
$this->addFlash(
'error',
'We got an error, CV was not sent'
);
}
$candidate = new Candidate();
$form = $this->createForm(CandidateType::class, $candidate);
}
return $this->render('cv/present.html.twig', [
'form' => $form->createView(),
]);
}
Answer the question
In order to leave comments, you need to log in
CandidateType
here and compare the resulting code.Request
=> transformation Response
, and that's what controllers are for.Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question