Closed
Description
For a form page like this (I removed excess code for simplicity):
class MovieType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('director', EntityType::class, [
'class' => MovieDirector::class,
// query builder etc
]);
$builder->add('name');
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Movie::class,
]);
}
}
and this subscriber:
public function onKernelTerminate(PostResponseEvent $event)
{
$this->em->clear();
}
with usual controller code:
public function editMovieAction(Movie $movie, Request $request): Response
{
$em = $this->getDoctrine()->getManager();
$form = $this->createForm(MovieType::class, $movie);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em->flush();
return $this->redirectToRoute('movie_detailed', ['id' => $movie->getId()]);
}
return $this->render('movies/form.html.twig', [
'form' => $form->createView(),
'all_movies' => $$this->getDoctrine()->getRepository(Movie::class)->findAll(),
]);
}
I get this error on second form submission (because form was invalid):
If I remove $em->clear() from kernel.terminate
event, it doesn't happen but since $em is shared, other user sees the changes.
The reason I put that code is so identity map doesn't get filled up quickly since it is shared among users. Also, it allows me to work on entities directly without the need for creating DTO classes.
Same problem happens if I put it in all other events like kernel.request, kernel.controller... doesn't change anything.
Any idea?
Btw, I really like this package. I get around 10ms on php7.1 compared to 170ms with server:run
.
Metadata
Metadata
Assignees
Labels
No labels