I'm using KnpPaginatorBundle for a page. In this page, I use a hand-created filter, which gives this
So if I enter something in the form, it will process the request and show as agreed. The problem is when I ask to sort by 'ID'.
This problem occurs when I make a filter on the name or service, and I ask to order by ID
I have the following error message:
This form should not contain extra fields
What should I do to stop this error?
My controller is :
/**
* Undocumented function
*
* @Route("/rh3", name="rh_index3")
*
* @param PaginatorInterface $paginator
* @param Request $request
* @param ObjectManager $manager
* @param UserRepository $repo
* @return void
*/
public function index3(PaginatorInterface $paginator, Request $request, UserRepository $repo)
{
$search = new UserSearch();
$form = $this->createForm(UserSearchType::class, $search);
$form->handleRequest($request);
$users = $repo->getUsersSearch($search);
$pagination = $paginator->paginate(
$users,
$request->query->getInt('page', 1),
7
);
return $this->render('rh/index3.html.twig', [
'pagination' => $pagination,
'form' => $form->createView(),
]);
}
And my Twig:
{% extends "base.html.twig" %}
{% block body %}
<div class="jumbotron">
<div class="container">
{{form_start(form)}}
<div class="form-row align-items-end">
<div class="col">
{{form_row(form.name)}}
</div>
<div class="col">
{{form_row(form.service)}}
</div>
<div class="col">
<div class="form-group">
<button type="submit" class="btn btn-primary">Rechercher</button>
</div>
</div>
</div>
{{form_end(form)}}
</div>
</div>
<table class="table table-hover align-items-center">
<thead>
<tr>
<th>{{ knp_pagination_sortable(pagination, 'Id', 'u.id') }}</th>
<th>Nom</th>
<th>Service</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for user in pagination %}
<tr {% if loop.index is odd %} class="color" {% endif %}>
<td>{{user.id}}</td>
<td>{{user.fullName}}</td>
<td>{{user.groupe.nom}}</td>
<td>
<a href="#" class="btn btn-primary">Voir</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="navigation">
{{knp_pagination_render(pagination)}}
</div>
{% endblock %}
Thanks for your help !
in your UserSearchType add this option:
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'allow_extra_fields' => true,
));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.