Hello. Can you please tell me if you can do the following?
I wanted to sort the articles by rating, the rating is calculated through this module https://github.com/hauntd/yii2-vote .
Something like this, only views is a field from a table with articles, and I need to sort by a field from a table with a rating:

<?php usort($competition, function ($a, $b) { return ($b['views'] - $a['views']); }) ?> <?php foreach ($competition as $item1): ?> ... 

Tied the model, tried it like this:

 <?php usort($competition, function ($a, $b) { return ($b->aggregate['rating'] - $a->aggregate['rating']); }) ?> <?php foreach ($competition as $item1): ?> ... 

The order of the articles is changing, but not as much as we would like.

  • and how it was wanted, and how it changes? If you need to expand to the other side, then change $b with $a some places - teran
  • @teran now sorts by views, normally joxi.ru/brRjnNQtPYLLr1 , if done in the second example it turns out like this in joxi.ru/Dr819w4TazJlm6 , the post with the highest rating is not the first and those who don’t have it in front of it go. - Alexey

0