Let's say I have an entity A with columns ID, foo, and bar which are either strings, integers or DateTime objects. This entity has all of the standard getters like getId(), getFoo(), and getBar().
In my controller, I have an object that is of another entity called B. The relationship between B and A is one to many. The getAllA() function finds all A associated with B which will return a Doctrine ArrayCollection. So with the object in the controller, I invoke
$paginator = $this->get('knp_paginator');
$paginatedObject = $paginator->paginate(
$object->getAllA(),
$this->get('request')->query->get('page', 1),
3
Now pagination works fine, but how do I sort? In the table header row I have
{{ knp_pagination_sortable(paginatedObject, 'ID', '???????????????') }}
but what goes in for the question marks?
You could use a DQL query like
and then the third parameter would be 'o.id'
source