after multiple research I come to ask for your help.
I created several pages in my symfony project, this my controller code:
public function liste(Request $request){
$users = $this->getDoctrine()
->getRepository(VicidialUsers::class)
->findAll();
return $this->render('user/list_users.html.twig', array(
'users' => $users
));
}
public function nouveau(Request $request): Response
{
$user = new VicidialUsers();
$form = $this->createForm(VicidialUsersType::class , $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
$this->get('session')->getFlashBag()
->add('notice', 'L\'utilisateur à été bien ajouter');
//clear form values after successful form submission
unset($user);
unset($form);
$user = new VicidialUsers();
$form = $this->createForm(VicidialUsersType::class , $user);
}
return $this->render('user/adduser.html.twig', array(
'form' => $form->createView()
));
}
public function edit(Request $request , $userId){
$user = new VicidialUsers();
$user = $this->getDoctrine()->getRepository
(VicidialUsers::class)->find($userId);
$form = $this->createForm(VicidialUsersType::class , $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
$this->get('session')->getFlashBag()
->add('notice', 'L\'utilisateur a été bien modifier');
}
return $this->render('user/edituser.html.twig', array(
'form' => $form->createView() ,'user' => $user
));
}
Only problem the page returned incorrectly in the case of editing or adding a new user
This is the user list display: 127.0.0.1:8000/utilisateurs:
[![User List][1]][1]
in the case of edit: 127.0.0.1:8000/user/edit/3:
the template is returned incorrectly
[![Edit User][2]][2]
This is my template code for adduser.html.twig
{% extends 'base.html.twig'%}
{% block body %}
<div class="container-fluid">
<h1 class="h3 mb-4 text-gray-800">Ajouter un nouvel utilisateur</h1>
</div>
<div class="col-md-12">
{% for flashMessage in app.session.flashbag.get('notice') %}
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa fa-check"></i>{{ flashMessage }}</h4>
</div>
{% endfor %}
<!-- general form elements -->
<div class="box box-primary">
<!-- form start -->
<form method="post">
<div class="box-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>{{ form_label(form.user) }}</label>
{{ form_widget(form.user) }}
<span class="text-danger">{{ form_errors(form.user) }}</span>
<div id="notification"></div>
</div>
<div class="form-group">
<label>{{ form_label(form.pass) }}</label>
{{ form_widget(form.pass) }}
<span class="text-danger">{{ form_errors(form.pass) }}</span>
</div>
<div class="form-group">
<label>{{ form_label(form.fullName) }}</label>
{{ form_widget(form.fullName) }}
<span class="text-danger">{{ form_errors(form.fullName) }}</span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>{{ form_label(form.userLevel) }}</label>
{{ form_widget(form.userLevel) }}
<span class="text-danger">{{ form_errors(form.userLevel) }}</span>
</div>
<div class="form-group">
<label>{{ form_label(form.userGroup) }}</label>
{{ form_widget(form.userGroup) }}
<span class="text-danger">{{ form_errors(form.userGroup) }}</span>
</div>
<div class="form-group">
<label>{{ form_label(form.phoneLogin) }}</label>
{{ form_widget(form.phoneLogin) }}
<span class="text-danger">{{ form_errors(form.phoneLogin) }}</span>
</div>
<div class="form-group">
<label>{{ form_label(form.phonePass) }}</label>
{{ form_widget(form.phonePass) }}
<span class="text-danger">{{ form_errors(form.phonePass) }}</span>
</div>
</div>
</div>
</div><!-- /.box-body -->
{{ form_rest(form) }}
<div class="box-footer">
<input type="submit" class="btn btn-primary" value="Ajouter" />
</div>
</form>
{% endblock %}
how can I solve this problem?