I am having trouble properly implementing knp paginator's sorting functionality into my Symfony2 application. I believe that the reason I am running into problems is because I don't know how FOSElastica builds queries from its built-in paginator, and therefore do not know what parameters to pass to knp_pagination_sortable(...)
in my twig file. This is how I render my paginator in my controller:
$finder = $this->get('fos_elastica.finder.employees.employee');
$paginator = $this->get('knp_paginator');
// $name is a parameter that is properly passed to my action function in
// the controller
$knp = $paginator->paginate(
$finder->createPaginatorAdapter($name),
$this->get('request')->get('page', $page),
25
);
This is the part of the twig file where I try to implement the sorting functionality:
<table border="1">
<tr>
<th>{{ knp_pagination_sortable(my_pager, 'Employee Number', 'emp_no') }}</th>
<th>{{ knp_pagination_sortable(my_pager, 'First Name', 'first_name') }}</th>
<th>{{ knp_pagination_sortable(my_pager, 'Last Name', 'last_name') }}</th>
<th>{{ knp_pagination_sortable(my_pager, 'Birth Date', 'birth_date') }}</th>
<th>{{ knp_pagination_sortable(my_pager, 'Gender', 'gender') }}</th>
<th>{{ knp_pagination_sortable(my_pager, 'Hire Date', 'hire_date') }}</th>
</tr>
{% for employee in my_pager %}
<tr>
<td>{{ employee.empNo }}</td>
<td>{{ employee.firstName }}</td>
<td>{{ employee.lastName }}</td>
<td>{{ employee.birthDate|date('M j Y') }}</td>
<td>{{ employee.gender }}</td>
<td>{{ employee.hireDate|date('M j Y') }}</td>
</tr>
{% endfor %}
</table>
Assuming $name is a properly formatted string, does anyone know what the query would look like inside of the PaginatorAdapter object? I tried to var_dump it but the query is a private parameter and does not have a get method (of course).