Skip to content

Instantly share code, notes, and snippets.

@dbeuchler
Last active December 14, 2015 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbeuchler/5038457 to your computer and use it in GitHub Desktop.
Save dbeuchler/5038457 to your computer and use it in GitHub Desktop.
This method helps you to sort your entity request in an Symfony2 entity!
/**
* This method helps you to sort your entity request in an Symfony2 entity!
*
* Please, share your tips commenting here:
* https://gist.github.com/5038457
*
* Author: @dbeuchler
*
* (Tested and used with doctrine 2.x and Symfony 2.0.x, 2.1.x)
*/
public function getProductsSortedByPositionInGroup()
{
$arr = $this->product->toArray();
usort($arr, function($a, $b) {
if ($a->getPositionInGroup() > $b->getPositionInGroup()) {
return 1;
}
});
return $arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment