I don't understand where should I put my form code in my Symfony 4 project. As I understand you should not have business logic in controller but you need to extend Controller to use $this->createForm.
class HomeController extends Controller
{
public function index(Request $request)
{
$article = new Article();
$form = $this->createForm(ArticleType::class, $article);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$article = $form->getData();
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($article);
return $this->redirect("/");
}
return $this->render('home/home.html.twig', [
'form' => $form->createView()
]);
}
}
Thanks